Lab 1 - Haonan Yu - MAT 275
Table of Contents
MAT 275 MATLAB LAB 1 NAME: Haonan Yu ..................................................................... 1
LAB DAY and TIME:F 1:30 PM - 2:20 PM ........................................................................... 1
Instructor:Salinas ................................................................................................................. 1
Exercise 1 .......................................................................................................................... 1
Exercise 2 .......................................................................................................................... 2
Exercise 3 .......................................................................................................................... 4
Exercise 4 .......................................................................................................................... 4
Exercise 5 .......................................................................................................................... 5
Exercise 6 a ....................................................................................................................... 9
Exercise 6 b ..................................................................................................................... 10
MAT 275 MATLAB LAB 1 NAME: Haonan Yu
LAB DAY and TIME:F 1:30 PM - 2:20 PM
Instructor:Salinas
Exercise 1
theta=[0,pi/3,pi/2,(2*pi)/3,pi,(4*pi)/3] %give the value of theta
r=3%give the value of r
x=r*cos(theta)
y=r*sin(theta)
r=sqrt((x.^2)+(y.^2)) % make that x and y satisfy the equation of the
circle
theta =
0 1.0472 1.5708 2.0944 3.1416 4.1888
r =
3
x =
3.0000 1.5000 0.0000 -1.5000 -3.0000 -1.5000
1
Lab 1 - Haonan Yu - MAT 275
y =
0 2.5981 3.0000 2.5981 0.0000 -2.5981
r =
3.0000 3.0000 3.0000 3.0000 3.0000 3.0000
Exercise 2
t=linspace(1,10,46);% creat a vector
y=exp(t./20).*cos(t)./(t.^2+4);% make y be a equation
%Part(a)
figure;
plot(t,y,'black--');% plot the graph
title('y=exp(t./20).*cos(t)./(t.^2+4)');% creat a title
%Part(b)
figure;
plot(t,y,'o');% plot the graph
title('y=exp(t./20).*cos(t)./(t.^2+4)');% creat a title
figure;
plot(t,y,'o-');% plot the graph
title('y=exp(t./20).*cos(t)./(t.^2+4)');% creat a title
2
0.05
7 7
oO
6
O
5
Q
9
4
“0.05
Oo
0.05
-0.05
Lab 1 - Haonan Yu - MAT 275
3
Lab 1 - Haonan Yu - MAT 275
Exercise 3
t=0:0.1:30;% creat a vector
x=sin(t);
y=cos(t);
z=t;
plot3(x,y,z)% plot the graph
grid on
Exercise 4
x=linspace(-pi,pi);
y=sin(x);
z=x-(x.^3)/6+(x.^5)/120;
plot(x,y,'r',x,z,'--')% plot the graph
grid on;
axis tight;
4
Lab 1 - Haonan Yu - MAT 275
Exercise 5
run 'ex5.m';
% function ex5
% x=linspace(0,5); %define the vector x in the interval [0,5]
% y1=f(x,-2); %compute the solution with C=-2
% y2=f(x,0); %compute the solution with C=0
% y3=f(x,2); %compute the solution with C=2
% plot (x,y1,'r',x,y2,'--',x,y3,'b')
% title('Solutions to dy/dx = x.^2-2x')
% legend('y(0)=-2','y(0)=0','y(0)=2','location','northwest')
% end
% function y=f(x,C)
% y=(x.^3/3)-x.^2+C
% end
y =
Columns 1 through 7
-2.0000 -2.0025 -2.0099 -2.0218 -2.0381 -2.0584 -2.0826
Columns 8 through 14
-2.1103 -2.1413 -2.1753 -2.2121 -2.2515 -2.2931 -2.3367
5
Lab 1 - Haonan Yu - MAT 275
Columns 15 through 21
-2.3821 -2.4290 -2.4771 -2.5262 -2.5760 -2.6263 -2.6768
Columns 22 through 28
-2.7272 -2.7773 -2.8269 -2.8756 -2.9233 -2.9696 -3.0143
Columns 29 through 35
-3.0571 -3.0979 -3.1362 -3.1720 -3.2049 -3.2346 -3.2609
Columns 36 through 42
-3.2835 -3.3023 -3.3168 -3.3270 -3.3324 -3.3329 -3.3282
Columns 43 through 49
-3.3180 -3.3022 -3.2803 -3.2522 -3.2176 -3.1763 -3.1279
Columns 50 through 56
-3.0723 -3.0091 -2.9382 -2.8593 -2.7720 -2.6762 -2.5716
Columns 57 through 63
-2.4579 -2.3348 -2.2022 -2.0598 -1.9072 -1.7443 -1.5708
Columns 64 through 70
-1.3864 -1.1909 -0.9840 -0.7654 -0.5350 -0.2923 -0.0373
Columns 71 through 77
0.2304 0.5111 0.8049 1.1122 1.4332 1.7682 2.1174
Columns 78 through 84
2.4810 2.8594 3.2528 3.6615 4.0856 4.5256 4.9815
Columns 85 through 91
5.4538 5.9426 6.4482 6.9708 7.5107 8.0683 8.6436
Columns 92 through 98
9.2371 9.8489 10.4792 11.1285 11.7969 12.4846 13.1920
Columns 99 through 100
13.9193 14.6667
6
Lab 1 - Haonan Yu - MAT 275
y =
Columns 1 through 7
0 -0.0025 -0.0099 -0.0218 -0.0381 -0.0584 -0.0826
Columns 8 through 14
-0.1103 -0.1413 -0.1753 -0.2121 -0.2515 -0.2931 -0.3367
Columns 15 through 21
-0.3821 -0.4290 -0.4771 -0.5262 -0.5760 -0.6263 -0.6768
Columns 22 through 28
-0.7272 -0.7773 -0.8269 -0.8756 -0.9233 -0.9696 -1.0143
Columns 29 through 35
-1.0571 -1.0979 -1.1362 -1.1720 -1.2049 -1.2346 -1.2609
Columns 36 through 42
-1.2835 -1.3023 -1.3168 -1.3270 -1.3324 -1.3329 -1.3282
Columns 43 through 49
-1.3180 -1.3022 -1.2803 -1.2522 -1.2176 -1.1763 -1.1279
Columns 50 through 56
-1.0723 -1.0091 -0.9382 -0.8593 -0.7720 -0.6762 -0.5716
Columns 57 through 63
-0.4579 -0.3348 -0.2022 -0.0598 0.0928 0.2557 0.4292
Columns 64 through 70
0.6136 0.8091 1.0160 1.2346 1.4650 1.7077 1.9627
Columns 71 through 77
2.2304 2.5111 2.8049 3.1122 3.4332 3.7682 4.1174
Columns 78 through 84
4.4810 4.8594 5.2528 5.6615 6.0856 6.5256 6.9815
Columns 85 through 91
7.4538 7.9426 8.4482 8.9708 9.5107 10.0683 10.6436
7
Lab 1 - Haonan Yu - MAT 275
Columns 92 through 98
11.2371 11.8489 12.4792 13.1285 13.7969 14.4846 15.1920
Columns 99 through 100
15.9193 16.6667
y =
Columns 1 through 7
2.0000 1.9975 1.9901 1.9782 1.9619 1.9416 1.9174
Columns 8 through 14
1.8897 1.8587 1.8247 1.7879 1.7485 1.7069 1.6633
Columns 15 through 21
1.6179 1.5710 1.5229 1.4738 1.4240 1.3737 1.3232
Columns 22 through 28
1.2728 1.2227 1.1731 1.1244 1.0767 1.0304 0.9857
Columns 29 through 35
0.9429 0.9021 0.8638 0.8280 0.7951 0.7654 0.7391
Columns 36 through 42
0.7165 0.6977 0.6832 0.6730 0.6676 0.6671 0.6718
Columns 43 through 49
0.6820 0.6978 0.7197 0.7478 0.7824 0.8237 0.8721
Columns 50 through 56
0.9277 0.9909 1.0618 1.1407 1.2280 1.3238 1.4284
Columns 57 through 63
1.5421 1.6652 1.7978 1.9402 2.0928 2.2557 2.4292
Columns 64 through 70
2.6136 2.8091 3.0160 3.2346 3.4650 3.7077 3.9627
Columns 71 through 77
4.2304 4.5111 4.8049 5.1122 5.4332 5.7682 6.1174
8
Lab 1 - Haonan Yu - MAT 275
Columns 78 through 84
6.4810 6.8594 7.2528 7.6615 8.0856 8.5256 8.9815
Columns 85 through 91
9.4538 9.9426 10.4482 10.9708 11.5107 12.0683 12.6436
Columns 92 through 98
13.2371 13.8489 14.4792 15.1285 15.7969 16.4846 17.1920
Columns 99 through 100
17.9193 18.6667
Exercise 6 a
f=inline('x.^2+(x.*exp(y))/(y+1)','x','y')% make f be a euqation
f(-1,2)
f =
9
Lab 1 - Haonan Yu - MAT 275
Inline function:
f(x,y) = x.^2+(x.*exp(y))/(y+1)
ans =
-1.4630
Exercise 6 b
clear f%clear the value of f
f(-1,2)
% function p=f(x,y)
% p=x.^2+(x.*exp(y))/(y+1) ;
% end
ans =
-1.4630
10