Math 111: MATLAB Assignment 1
Plotting functions with MATLAB
Due Date: OCTOBER 11, 2007
The example
below shows how MATLAB is used to plot simple functions. To begin, click on
the Matlab icon on your desktop to open a Matlab screen. Click on File ->
New -> m-file to create a new file. Cut-and-paste, or type in, the code
below. Save as an .m file, e.g., plotcode.m. Now, at the >>
prompt in the Command window, type the file name plotcode. The
program will run and the plots should appear. Consult the MATLAB TA's if you
have any questions.
x = [-0.25: 0.001: 0.25];
y = sin(10 .* x);
z = cos(10 .* x);
w = (y + z) ./ 2;
plot(x,y)
hold on
plot (x, z, ':')
plot (x, w, '*')
grid on
hold off
In the first statement, x
is an array of numbers from -0.25 to 0.25 in steps of 0.001. The ';'
suppresses display of the array. The first plot command creates the
graph of sin 10 x (note the "." in ".*" and "./" for multiplication
and division, respectively). The hold on command allows a second
graph to be overlaid on the first (instead of replacing it). The ':' in the
second plot command causes the graph of cos 10 x to be dotted, to
distinguish it from the solid graph of sin 10 x. The grid on
command is optional; it puts the horizontal and vertical grid lines on the
graph.
After running the above example, do the following to hand in.
For this assignment, you should hand in at most 3 pages, consisting of two
plots and your code.
◙ Use MATLAB to plot sin(x)./x on an interval [-30:30] (make sure that the graph looks smooth).
◙ What is the limit of this function as x approaches zero?
◙ On a separate graph, plot 2./sqrt(3+x.^2) and -1./sqrt(2+x.^2) on an interval [-20:20].
IF YOU NEED HELP CONSULT THE FOLLOWING MATLAB TA’S: |
|||
U:082607