Self-check exercise: Basic Plotting
-
Experiment with different line-marker format in this script. In the command
plot(x,y,[L R],[0 0], ':')
the first set of data,
x
and y, are plotted using the default format — solid line — while the second set of data, the points (L,0) and (R,0), are plotted according to the format specification ':' — a dotted line. The format specificaton is enclosed in quotation marks. Here are a few example format specifications:- '-' for solid line,
- '.' for a dot at each data point point,
- 'r' for red
- 'g-' for a green solid line,
- 'b+:' for a blue dotted line with a cross marking each data each point, etc.
Type help plot in MATLAB's Command Window to see a complete list of options.
-
Modify the same script to use the colon expression instead of the built-in function linspace to create the vector of x values. Recall that
linspace
allows you to specify the number of points while the colon expression allows you to specify the increment between points. Write a colon expression that matches thelinspace
function call exactly. -
Write a script that displays in a single figure window a plot of the functions x, x2, x3, x4, and x5 across the interval [0,1].
The following exercises are taken from the manuscript "Insight Through Computing: A Matlab Introduction to Computational Science Engineering" by Van Loan and Fan.