Data may be graphed using the plot(x,y)-function, x and y being equalsized vectors, which denote the coordinates of the data points to be plotted. A third optional argument plot(x,y,option) specifies plot options like colors and symbols. The graphic may then be decorated (axis, title) and exported as encapsulated-postscript file for inclusion in text documents. With hold (or hold on) the graphic gets locked so that subsequent plot commands use the same window. Repeating hold (or hold off) deletes the graphic.
plots x versus y using option x and y are equalized vectors. option is a string, specifying color (one of r,g,b,y,m,c,w,k) and symbol (one of +,*,o,x). Default: blue lines.
Logarithmic and semi-logarithmic plots are provided with the functions loglog, linlog and loglin.
Here are the major plot methods:
|plot(x,y [option])||Plot x versus y|
|loglog(x,y [option])||logarithmic plot|
|linlog(x,y [option])||semi-logarithmic plot|
|loglin(x,y [option])||semi-logarithmic plot|
|print(name )||write graphic in eps-file|
Let as show a simple example of plotting sin(x) between 0 and 10 with a step 0.1
However, one can overlay these plots using the “hold” method:
You can plot symbols as well:Run this plot to see its output.
Now let us draw data points with errors and overlay a Gaussian function . First we build a function “fit”, draw data points and overlay the Gaussian function at fixed values [1.4912 3.9911 1.4481 ]
Example 1 let us plot the function: in the range x=0.01…100 linear and logarithmic. The code is below:
Example 1a let us plot the function cos(x):
Example 2: Display of Lissajous-figures: From the vector t=0:0.1:4*pi; create the trigonometric expressions x=sin(0.5*t+1); and y=cos(1.5*t);. The plot x vs. y is called Lissajous-figure. Create different figures by variating the constants 0.5,1,1.5 in the definition. Partial solution:
Example 3 Calculate the first 100 elements of the sequences
Plot versus using the command plot(n, xn). Variate the plotoptions (colors, symbols).
Example 4 Plot the data points of the following table using plot and colored symbols. Calculate the linear regression using polyfit, and plot the regression line in the same graph. Add title and labels, and export the graphic to a file suitable for inclusion in a text document.
x 0 1 2 3 4 5 6 7 8 9 y -3.1 -0.7 1.8 4.1 6.2 8.9 11.3 13.5 16 18.3