Introduction To Matlab PDF
Introduction To Matlab PDF
introductio
MATLAB has an excellent set of graphic tools. Plotting a given data set or the results
of computation is possible with very few commands. You are highly encouraged to plot
mathematical functions and results of analysis as often as possible. Trying to understand
mathematical equations with graphics is an enjoyable and very efficient way of learning math-
ematics. Being able to plot mathematical functions and data freely is the most important
step, and this section is written to assist you to do just that.
>> x = [1 2 3 4 5 6];
>> y = [3 -1 2 4 5 1];
>> plot(x,y)
Note: The plot functions has different forms depending on the input arguments. If y is a
vector plot(y)produces a piecewise linear graph of the elements of y versus the index of the
elements of y. If we specify two vectors, as mentioned above, plot(x,y) produces a graph
of y versus x.
For example, to plot the function sin (x) on the interval [0 , 2π], we first create a vector of
x values ranging from 0 to 2 π, then compute the sine of these values, and finally plot the
result:
1
5
−1
1 2 3 4 5 6
>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x,y)
Notes:
– starts at 0,
– takes steps (or increments) of π/100,
– stops when 2π is reached.
2
REFERENCES
[1] The MathWorks Inc. MATLAB 7.0 (R14SP2). The MathWorks Inc., 2005.