MAT 275 MATLAB LAB 1 NAME: Naazaneen Maududi
LAB DAY and TIME: Monday,9:00a.m
Instructor: Dr. Ahn
Exercise 1:
t = [0;pi/4;pi/2;3*pi/4;5*pi/4]; % values of theta
r = 2; % compute the row vectors x and y
x = r*cos(t); % coordinates of the point, with r being the radius
y = r*sin(t); % coordinates of the point, with r being the radius
q = sqrt(x.^2+y.^2); %check that x and y satisfy the equation of a circle
Command output:
q =
2
2
2
2
2
x =
2.0000
1.4142
0.0000
-1.4142
-1.4142
y =
0
1.4142
2.0000
1.4142
-1.4142
Exercise 2:
(A)
t = 1:.1:10; % vector t with 91 elements
y = (exp(t./10).*sin(t))./(t.^2+1); % function of y
plot(t,y,'k') % plot function of y in black
title('e^(t/10)*sin(t)/(t^2+1)') % title of the plot with the expression of y
Command Output:
1 2 3 4 5 6 7 8 9 10
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6 e
(
t/10)*sin(t)/(t
2
+1)
(B part 1)
t = 1:.1:10; % vector t with 91 elements
y = (exp(t./10).*sin(t))./(t.^2+1); % function of y
plot(t,y,'o') % plot function of y in black
title('e^(t/10)*sin(t)/(t^2+1)') % title of the plot with the expression of y
Command Output:
1 2 3 4 5 6 7 8 9 10
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6 e
(
t/10)*sin(t)/(t
2
+1)
(B part 2)
t = 1:.1:10; % vector t with 91 elements
y = (exp(t./10).*sin(t))./(t.^2+1); % function of y
plot(t,y,'o-') % plot function of y in black
title('e^(t/10)*sin(t)/(t^2+1)') % title of the plot with the expression of y
Command Output:
1 2 3 4 5 6 7 8 9 10
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6 e
(
t/10)*sin(t)/(t
2
+1)
Exercise 3:
t = 0:0.1:20; % t is less than or equal to zero and greater than
or equal to 20
x = sin(t); % function of t
y = cos(t); % function of t
z = t; % function of t
plot3(x,y,z) % plots a circular helix
Command Output:
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1
0
5
10
15
20
Exercise Four:
x = linspace(0,pi,10000000); % vector of x in the intervals
(0,pi)
y = cos(x); % solution of y
z = (1-(x.^2./2)+(x.^4./4)); %solution of z
plot(x,y,'r',x,z,'--')% plots the two equations on the same plot
grid on % turns on the grid lines on the plot
Command Output:
Exercise 5:
function ex5
x = 0:0.1: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,x,y2,'--',x,y3,':') % 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') % 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
Command Output:
C1=
-1
C2=
0
C3=
1
Exercise 6:
(A)
f = inline('x.^3+((y.*exp(x))./(x+1))','x','y'); % function used as an inline so that x and y values
could be evaulated
Command Output:
x =
2
y =
-1
c = f(x,y)
c =
5.5370
(B)
function [ n ] = f(x,y )
here
% should give the same answer as part a
n = (x.^3+((y.*exp(x))./(x+1)));
end
Command Output:
f(2,-1)
ans =
5.5370