plot
plot
2)fplot function
See also
•Function plot
>>fplot(‘function’,[xmin xmax],’property’)
Example :
>>fplot(‘sin’,[0 2*pi],’r:’)
fplot function
• » fplot('sin(x)',[-pi pi])
fplot function
• » fplot('sin(x)',[-pi pi])
0.5
-0.5
-1
-2 0 2 Abdelrahman Mohamed fargly
5
fplot function
• » fplot('exp(-x)*sin(x)',[0 2])
fplot function
• » fplot('exp(-x)*sin(x)',[0 2])
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
0 0.5 1 1.5 2
Adding a grid
• You can use the command:
• grid on
• to add grid lines to your plot. This
increases the readability of the graph.
Adding a grid
• You can use the command:
• grid on
• to add grid lines to your plot. This
increases the readability of the graph.
• To remove these grid lines, use:
• grid off
Adding a grid
• » fplot('exp(x)-x-2',[-3 3])
• » grid on
Adding a grid
• » fplot('exp(x)-x-2',[-3 3])
• » grid on
20
15
10
-5
-3 -2 -1 0 1 2 3
3D Plotting
plot3 function
• The MATLAB function plot3 is used to
plot space curves.
plot3 function
• The MATLAB function plot3 is used to
plot space curves.
plot3 function
• The MATLAB function plot3 is used to
plot space curves.
plot3 Example 1
• Example: Plot the line
• x = t + 2, y = t - 2, z = t, 0 < t < 1
plot3 Example 1
• Example: Plot the line
• x = t + 2, y = t - 2, z = t, 0 < t < 1
>> t=0:0.01:1;
>> x=t+2;
>> y=t-2;
>> z=t;
>> plot3 (x,y,z,'r.')
>> grid on
plot3 Example
plot3 Example 2
plot3 Example 2
plot3 Example
plot3 Example 3
plot3 Example 3
t=0:0.01:10*pi;
x=cos(t);
y=sin(t);
z=t;
plot3(x,y,z,'r.')
grid on
plot3 Example
plot3 function
plot3 Example 4
• Example: Plot together
• sin x, cos x
plot3 Example 4
• Example: Plot together
• sin x, cos x
x=0:0.01:3*pi;
y1=zeros(size(x));
y2=ones(size(x));
z1=sin(x);
z2=cos(x);
plot3(x,y1,z1,'.r',x,y2,z2,'.g')
grid on
plot3 Example 4
mesh function
mesh function
mesh function
meshgrid by example
>> x=0:2
x = 0 1 2
>> y=0:2
y = 0 1 2
>> [X,Y]=meshgrid(x,y)
meshgrid by example
>> x=0:2
x = 0 1 2
>> y=0:2
y = 0 1 2
>> [X,Y]=meshgrid(x,y)
X = 0 1 2
0 1 2
0 1 2
Y = 0 0 0
1 1 1
2 2 2
mesh Example 1
mesh Example 1
x=-3:0.01:3;
y=-3:0.01:3;
[X,Y]=meshgrid(x,y);
z=X.^2+Y.^2;
mesh(X,Y,z)
mesh Example 1
mesh Example 2
mesh Example 2
>> x=-3:0.1:3;
>> y=-3:0.1:3;
>> [X,Y]=meshgrid(x,y);
>> z=3-7*X+Y;
>> mesh(X,Y,z)
mesh Example 2
Function Used to
semilogx Create a graph with logarithmic scale for the x axis only
semilogy Create a graph with logarithmic scale for the y axis only
plotyy Create a graph with y-tick labels on the left and right side