You are on page 1of 11

NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2

200332 15/12/2021

EPF3109 Numerical and Computer Methods


Assignment 6: Developing Program using User-Defined Functions and
Function Files

Question 1

Step 1: On Editor window


function c=circleplot(x,y,R);
th = 0:0.01:2*pi;
x=R*cos(th)+x;
y=R*sin(th)+y;
c= plot(x,y);

Step 2: Click Save File and Run / Continue as circleplot.m

Step 3: On Command Window


a)
>> circleplot(3.5,2.0,8.5)
ans = -39.430
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

b)
>> circleplot(4.0,-1.5,10)
ans = -1.3201
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

Question 2

-
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

Step 1: On Editor window


function[Smax,Smin]=princstress(Sxx,Syy,Sxy);
Avg=(Sxx+Syy)./2;
R=sqrt(((Sxx-Syy)./2).^2+Sxy.^2);
Smax=Avg+R;Smin=Avg-R;

Step 2: Click Save File and Run / Continue princtress.m

Step 3: On Command Window


a)
>> [Smax,Smin]=princstress(-190,145,110)
Smax = 177.89
Smin = -222.89

b)
>> [Smax,Smin]=princstress(200,-50,150)
Smax = 270.26
Smin = -120.26
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

Question 3
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

Step 1: On Editor window


Circle.m
function[x_1,y_1]=circle(x1,y1,r1)
ang1=0:0.1:2*pi;
xp1=r1.*cos(ang1);
yp1=r1.*sin(ang1);
x_1=x1+xp1;
y_1=y1+yp1;

main.m
a=0.5;
b=0.5;
r1=0.3;
[x11,y11]=circle(a,b,r1);
c=2;
d=1;
r2=0.4;
[x22,y22]=circle(c,d,r2);
e=3;
f=1;
r3=0.4;
[x33,y33]=circle(e,f,r3);
g=1;
h=2;
r4=0.5;
[x44,y44]=circle(g,h,r4);
i=2.5;
j=2;
r5=0.4;
[x55,y55]=circle(i,j,r5);
plot(x11,y11,x22,y22,x33,y33,x44,y44,x55,y55);
xlabel('x_c','fontsize',15);
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

ylabel('y_c','fontsize',15);

Step 2: Click Save File and Run / Continue both circle.m and main.m file

Step 3: On Command Window


>> main
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

Question 4

a)
Step 1: On Editor window
tau1.m
function[y1]=tau1(m,u)
m1=10;
u=0.5;
y1=m1.*u;
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

tau2.m
function[y2]=tau2(m,u)
m2=10;
u=0.5;
y2=m2.*u;

tau3.m
function[y3]=tau3(m,u)
m3=10;
u=0.5;
y3=m3.*u;

main5.m
x=input('Please enter the number of emulsifier added: ');

if x>0 & x<=2


sf1=tau1;
fprintf('The shear flow of the syrup is %5.2f kPa \n',sf1)
elseif x>2 & x<=4
sf2=tau2;
fprintf('The shear flow of the syrup is %5.2f kPa \n',sf2)
elseif x==5
sf3=tau3;
fprintf('The shear flow of the syrup is %5.2f kPa \n',sf3)
else
disp('Please enter a value between 1 to 5')
end

Step 2: Click Save File and Run / Continue all tau1.m, tau2.m, tau3.m and main5.m file

Step 3: On Command Window


>> main5
Please enter the number of emulsifier added: 2
The shear flow of the syrup is 5.00 kPa
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

Question 5

Step 1: On Editor window


VolFuel.m
function V=VolFuel(h)
r=15;
H=40;
if h<=r
V=pi.*h.^2.*(3.*r-h)./3;
elseif h>r & h<=(r+H)
V=2.*pi*r.^3./3+pi.*r^2.*(h-r);
elseif h>(H+r) & h<=(H+2*r)
V=4.*pi.*r^3./3+pi.*r.^2*H-pi.*(H+2.*r-h).^2.*(r-H+h)./3;
End

assignment6q5.m
h=0:0.25:70;
n=length(h);
NUR NASHWA ALIA BINTI KHAIRUDIN EPF3109-2
200332 15/12/2021

for i=1:n
V(i)=VolFuel(h(i));
end
plot(h,V)
xlabel('h (inch)')
ylabel('V (inch^3)')

Step 2: Click Save File and Run / Continue both VolFuel.m and assignment6q5.m file

Step 3: On Command Window


>> assignment6q5

You might also like