1 / 6100%
LAB 1 - Your Name - MAT 275
Exercise 1
NOTE: Please suppress output - i.e., use a semicolon ';' at the end of any commands for which the output is not
necessary to answer the question. Delete these notes before turning in.
Define input variable theta as discretized row vector (i.e. array)
theta = [0 pi/8 pi/6 pi/5 6*pi/5 7*pi/6 8*pi/7];
Define radius
r = 5;
Define x and y in terms of theta and r
x = r*cos(theta);
y = r*sin(theta);
Check that x and y satisfy the equation of a circle
r2 = sqrt(x.^2*y.^2);
Explain results here. Do x and y satisfy the equation of a circle? Why or why not?
Yes x and y do satisfy the equation of a circle because when calculating r2 the length is equal to that of
the radius.
How does the vector output at the end confirm your answer?
The vector output at the end confirm the answer because r2 = r
Exercise 2
Define t-vector
t = [2:.1:10];
Define y-vector
y= (exp(t/20).*cos(2*t))./(0.3*t.^3+18);
Part (a)
Plot results (should have 3 plots total)
figure;
plot(t,y,'k');
title('exp(t/20)*cos(2*t)/0.3*t^3+18')
1
Part (b)
Plot results as data points only and as data points with line.
figure; %creates another figure window
plot(t,y,'o');
title('exp(t/20)*cos(2*t).0.3*t^3+18')
figure;
plot(t,y,'o-')
title('exp(t/20)*cos(2*t)/0.3*t^3+18')
2
Exercise 3
Create t-vector (choose enough elements so that plot is smooth!)
t = linspace(0,5);
Define x, y, x components in terms of t
x = 4*cos(5*t);
y = 4*sin(5*t);
z = 8*t;
Plot results
figure;
plot3(x,y,z);
xlabel('4*cos(5*t)');
ylabel('4*sin(5*t)');
zlabel('8*t');
grid on
3
NOTE: if graph does not look smooth use more elements in your t-vector -- i.e. use smaller stepsize between
elements. Delete these notes before submission.
Exercise 4
Define input variable as vector
x= linspace(-pi/3,pi/3);
Define y and z
y = sin(3*x);
z =3*x-9/2*x.^3;
Plot results
figure;
plot(x,y,'r',x,z,'--b');
axis tight;
grid on
4
Exercise 5
NOTE: you must create the M-file ex5.m separately and invoke it here in your livescript file. Delete these notes
before submission.
type DEQ1.m
x = linspace(0,4);
y1 = 11/2*x.^2+11/3*x.^3-4*sin(x)+30;
y2 = 11/2*x.^2+11/3*x.^3-4*sin(x)+60;
y3 = 11/2*x.^2+11/3*x.^3-4*sin(x)+90;
plot (x,y1,x,y2,'--r',x,y3,'.b')
title ('Solutions to dy/dx = 11x + 14x^2 - 4cos(x)')
legend ('C= 30','C= 60','C= 90')
function y = f(x,C)
y = 11/2*x.^2+11/3*x.^3-4*sin(x)+C
end
Run your M-file--i.e. execute the M-file
run 'DEQ1.m'
5
Exercise 6
Part (a)
Define g as anonymous function
g=@(x,y)x^2/y^2+cos(2*x*exp(4*y))/(x^5+7);
Evaluate g at the given values of x and y
g(9,-9)
ans = 1.0000
Part (b)
NOTE: You need to create a separate M-file (g.m) and invoke it in the main file, here. Erase these notes upon
submission.
Clear the function g out of the workspace
clear g;
g(9,-9)
ans = 1.0000
Print out g.m contents
type 'g.m'
function z = g(x,y)
z = x^2/y^2+cos(2*x*exp(4*y))/(x^5+7);
end
Evaluate g at the given values of x and y
g(9,-9)
ans = 1.0000
The End!!!
6
Students also viewed