Lab 1 - Your Name - MAT 275
Table of Contents
Exercise 1 .......................................................................................................................... 1
Exercise 2 .......................................................................................................................... 1
Exercise 3 .......................................................................................................................... 4
Exercise 4 .......................................................................................................................... 4
Exercise 5 .......................................................................................................................... 5
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/5 pi/3 pi/2 3*pi/2 4*pi/3 5*pi/4];
% Define radius.
r = 3;
% 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.
r=sqrt(x.^2+y.^2);
Explain results here. Do x and y satisfy the equation of a circle? Why or
%Yes because after running the r=sqrt(x.^2+y.^2) on the mathlab it
gave a r to 3.
% why not? How does the vector output at the end confirm your answer?
% Notice I did not include text in the same line where the double-
comment
% is. What this accomplishes is it does not add a title or create a
new
% section in the table of contents when you publish. Using single %
% starting in the line after the %% turns the comments black as
opposed to
% green.
Exercise 2
% Define t-vector.
1
Lab 1 - Your Name - MAT 275
t= 2:0.1:10;
% Define y-vector.
y = (exp(t./5).*cos(2.*t))./(0.2.*t.^2+13);
Part (a)
% Plot results (should have 3 plots total).
figure;
plot(t,y,'black');
title('y = (exp(t./5).*cos(2.*t))./(0.2.*t.^2+13);')
Part (b)
% Plot results as data points only and as data points with line.
figure; % creates a new figure window for next plot
plot(t,y,'o');
title('y = (exp(t./5).*cos(2.*t))./(0.2.*t.^2+13);')
figure; % creates another figure window
plot(t,y,'o-');
title('y = (exp(t./5).*cos(2.*t))./(0.2.*t.^2+13);')
2
025
O27
O15
-
iF
0.05
-
-.15
7
10
025
O2F
0.45
-
17
0.05
-
-0.05
re
-.15
7
10
Lab 1 - Your Name - MAT 275
3
Lab 1 - Your Name - MAT 275
Exercise 3
% Create t-vector (choose enough elements so that plot is smooth!)
t = 0:0.001:5;
% Define x,y,z components in terms of t.
x = 5.*cos(6.*t); y = 5.*sin(6.*t); z = 9.*t;
% Plot resuls.
figure;
plot3(x,y,z);
grid on
% 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 = (-pi/6):0.001:(pi/6);
% Define y and z.
y = sin(6.*x);
z = 6.*x-36.*x.^3;
4
Lab 1 - Your Name - MAT 275
% Plot results.
figure;
plot(x,y,'r-',x,z,'b--')
axis tight;
grid on;
Exercise 5
% NOTE: you must create the M-file ex5.m separately and invoke it here
in
% your main M-file (main file).
% Print out the code for your created M-file (do NOT submit M-file
% separately).
type 'ex5.m'
% Run your M-file--i.e., execute the M-file.
run 'ex5.m'
x=[0 8]
Error using type
File 'ex5.m' not found.
5