Math 485 (Sect 2) -- Mathematical Modeling

[ Tutorial page | Course home page ]

Section 2: plotting

MATLAB is very useful for plotting. Try
>> x = -pi:0.02:pi;
>> y = cos(x);
>> plot(x,y)
The ";" at the end of each line suppresses "echos." The first line creates a row vector consisting of equi-spaced numbers in the interval [-pi,pi]. The second vector applies the function cos to every member of x. The third creates the plot.

You can learn more about the plot command by

>> help plot
 PLOT   Linear plot. 
    PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
    then the vector is plotted versus the rows or columns of the matrix,
    whichever line up.  If X is a scalar and Y is a vector, disconnected
    line objects are created and plotted as discrete points vertically at
    X.

....
Last updated on February 4, 2008 by Kevin K. Lin