lab1_saad.rtf

Name: Saad Aldawsari Class: Mat275_lab

Time: Wednesday 6:00 pm

format compact

% MAT 275 MATLAB Assignment # 1

% Exercise 1

theta=0:pi/4:5*pi/4

theta =

0 0.7854 1.5708 2.3562 3.1416 3.9270

r=2

r =

2

x=r*cos(theta)

x=

2.0000 1.4142 0.0000 -1.4142 -2.0000 -1.4142

y=r*sin(theta)

y =

0 1.4142 2.0000 1.4142 0.0000 -1.4142

R=sqrt(x.^2+y.^2)

R =

2 2 2 2 2 2

% R is equal to the sqrt(x^2+y^2). All the values of R is equal to 2, so we can say that R=2=sqrt(x^2+y^2).

% Exercise 2 -a

t = 1:0.1:10;

y = (exp(t./10).*sin(t))./(t.^2+1);

plot(t,y,'k-');

title('y = (e^{t/10}*sin(t))/(t^2+1)');

file_0.wmf

% The above is the plot of y = e^(t/10)sin(t)/(t^2+1). The color code for black is k.

Name: Saad Aldawsari Class: Mat275_lab

Time: Wednesday 6:00 pm

% Exercise 2 - b

plot(t,y,'o')

file_1.emf

file_2.wmf

% After using ‘o’, my plot became a series of circles.

plot(t,y,'o-')

file_3.emf

file_4.wmf

% After using ‘o-’, my plot became a series of circles with a blue line coursing through.

Name: Saad Aldawsari Class: Mat275_lab

Time: Wednesday 6:00 pm

% Exercise 3

t = 0:0.05:20;

x = sin(t);

y = cos(t);

z = t;

plot3(x,y,z);

file_5.emf

file_6.wmf

% I used a lot of points for this one. The 3d plot showed me a spiral curve.

% Exercise 4

x = 0:0.02:pi;

y = cos(x);

z = 1-x.^2./2+x.^4./24;

plot(x,y,'r',x,z,'--'); grid on;

file_7.emf

file_8.wmf

% Using the code above, I was able to plot y and z in one graph.

Name: Saad Aldawsari Class: Mat275_lab

Time: Wednesday 6:00 pm

% Exercise 5

function ex5

% function ex5.m similar to myplot1.m

x = 0:0.2:4; % define the vector x in the interval [0,4]

y1 = f(x,-1); % compute the solution with C = -1

y2 = f(x,0); % compute the solution with C = 0

y3 = f(x,1); % compute the solution with C = 1

plot(x,y1,'r-',x,y2,'b-',x,y3,'k-'); % plot the three solutions with different line styles

title('Solutions to dy/dx = x+2'); % add a title

legend('C = -1','C = 0','C = 1','Location','northwest'); % add a legend

end

function y = f(x,C)

y = x.^2./2+2.*x+C % fill-in with the expression for the general solution

end

file_9.png

file_10.wmf

% Exercise 6-a

f = inline('x^3+y*exp(x)/(x+1)','x','y')

f =

Inline function:

f(x,y) = x^3+y*exp(x)/(x+1)

f(2,-1)

ans =

5.5370

% The value of the function when x = 2 and y = -1 is equal to 5.5370.

Name: Saad Aldawsari Class: Mat275_lab

Time: Wednesday 6:00 pm

% Exercise 6 - b

clear f

function z = f(x,y)

% function f.m

z = x^3+y*exp(x)/(x+1)

end

f(2,-1)

z =

5.5370

ans =

5.5370

diary off

% Just the same answer with 6-a, but different method.