Exercise 1 & 2 matlab algorithmic

5

Transcript of Exercise 1 & 2 matlab algorithmic

Page 1: Exercise 1 & 2 matlab algorithmic
Page 2: Exercise 1 & 2 matlab algorithmic

Exercise 1- question a and b:

x=fopen('input.txt'); C=textscan(x,'%f32','Headerlines',1,'Delimiter',','); for i=1:size(x,1); if x(i)<=0; y(i)=x(i)^2-cos(x(i))+exp(x(i)); elseif x(i)>0 && x(i)<=5; y(i)=x(i)^3-2*sin(x(i))+tan(x(i)); elseif x(i)>5 && x(i)<10; y(i)=5*x(i)-log(x(i))+sqrt(x(i)); elseif x(i)>=10; y(i)=x(i)^3-x(i)^2+x(i)+1; end; end; fclose(x); y=y' out=[x y] save output1.txt out -ASCII plot(x,y)

Page 3: Exercise 1 & 2 matlab algorithmic

Exercise 1c:-

syms x y z eq1=1/x+1/y-5/6; eq2=1/y+1/z-7/12; eq3=1/x+1/z-3/4; [x1 x2 x3]=solve(eq1,eq2,eq3)

Page 4: Exercise 1 & 2 matlab algorithmic

Exercise 2:-

Xo=[5] Uo=[6] n=[0.5] g=[9.81] t=0:2:120; t=t' for i=1:size(t,1); X(i)=Xo+Uo*t(i)+1/2*n*g*t(i)^2; U(i)=Uo+n*g*t(i); end; X=X' U=U' out=[X',U']; save output5.txt out -ASCII plot(t,X, 'Marker', 'O') hold on plot(t,U, 'color', 'r') hold off

Page 5: Exercise 1 & 2 matlab algorithmic