

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


MATLAB Problem Set 1
Print out the plots of each part of the following problems to hand. If you wish to economize on the amount of paper, you may use the command subplot (page 93 of the MATLAB Companion).
The first four problems can be done on the command line, although it is useful to put all the commands in an Mfile.
axis([0, 5, 0,4]).
f (x) =
cos x 1 + x^2
on the interval [0, 2 π]. a) Use the commands
x = linspace(0, 2*pi, 11); y = cos(x)./(1+x.^2); plot(x,y)
The result should be a polygonal line through the 11 points (xj , f (xj )), where xj = (2πj)/ 10 , j = 0, 1 ,... , 10. b) Do this in a different way with the commands
f = inline(’cos(x)./(1+x.^2)’) plot(x,f(x))
c) To make a smoother curve, increase the number of points.
x = linspace(0, 2pi, 21); plot(x,f(x)) x = linspace(0, 2pi, 51); plot(x,f(x))
t = linspace(0, 2pi, 101); x = 1+1.5cos(t); y = 2+1.5*sin(t); plot(x,y)
To make the circle look like a circle instead of an egg, use the command
axis equal. b) Use the command hold on. Then by changing the number of t points, draw the hexagon in this circle.
fn(x) =
1 + xn
for n = 1,... , 10. Use the command hold on to put all the graphs in the same figure.