Basic Plotting:: X (1 2 3 4 5 6) y (3 - 1 2 4 5 1) Plot (X, Y)
Basic Plotting:: X (1 2 3 4 5 6) y (3 - 1 2 4 5 1) Plot (X, Y)
MATLAB has an excellent set of graphics tools. Plotting a given data set or results
of computation is possible with a very few commands. Trying to understand
mathematical functions with graphics is an enjoyable and very ancient way of
learning mathematics. 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.
The MATLAB command used to plot the graph is “plot(x,y)”. For example, if the
vector x= (1; 2; 3; 4; 5; 6) and y=
(3; -1; 2; 4; 5; 1)
>> x= [1 2 3 4 5 6];
>> y= [3 -1 2 4 5 1];
>>plot(x,y)
Now try the following:
MATLAB enables you to add axis labels and titles. For example, using the graph
from the previous
example, add x- and y-axis labels.
>> xlabel (‘x = 0:2\pi’);
>>ylabel (‘sine of x’);
>>title (‘Plot of the Sine Function’)
Multiple data sets in one plot:
Multiple (x;y) pairs arguments create multiple graphs with a single call to plot. For
example, these statements plot
three plots related functions of x: y1=2 cos(x), y2=cos(x), and
y3=0.5*cos (x) in the interval 0 ≤ x ≤ 2Π
>> x= 0:pi/100:2*pi;
>>y1= 2*cos(x);
>>y2= cos (x);
>>y3= 0.5*cos (x);
>>plot (x, y1, ‘- -‘,x, y2, ‘- - ‘, x, y3, ‘:’)
>>xlabel (‘0 \leq x \leq 2\pi’)
>>ylabel (‘Cosine functions’)
>>legend (‘2*cos(x)’, ‘cos(x)’, ‘0.5*cos(x)’)
>>axis ([0 2*pi -3 3])
1. Given that x=-5+9i and y=6-2i, use MATLAB to show that x-y=1+7i, xy= -12+64i
and x/y= -1.2 + 1.1i
2. Use MATLAB to compute: 6(351.4 )+140.35
3. Use MATLAB to plot the functions y=4√(6x+1) and z=5e0.3x – 2x over the
interval 0<x<1.5
4. Use MATLAB to plot function s= 2 sin (3t+2) + √(5t+1) over the interval 0<t<5.
5. Plot exp(-x) sin(8x) for 0≤ x ≤2Π
6. Plot the function y= (4/Π) [(sin x) + (sin 3x)/3 + (sin 5x)/5 + (sin7x)/7] over the
interval –Π<x<Π. These are the first four terms of the Fourier Series
representation of a square wave.
7. Define a 4x3 matrix with zeros everywhere except the first line that is filled
with 1. Hint= use ones and zeros command
8. Use MATLAB to solve following set of equations.
6x - 4y + 8z = 112
-5x – 3y +7z = 75
14x + 9y – 5z = -67
9. Use MATLAB to find roots of 13x3 + 182x2 – 184x +2503 = 0