Documentos de Académico
Documentos de Profesional
Documentos de Cultura
>> x=linspace(-5,5,100);
>> plot(x,x.^2)
Output
Symbol Description
bblue
ggreen
rred
ccyan
mmagenta
yyellow
kblack
wwhite
.point
ocircle
xx-mark
+plus
*star
ssquare
ddiamond
vtriangle (down)
triangle (up)
<triangle (left)
>triangle (right)
ppentagram
hhexagram
solid
:dotted
.dashdot
dashed
(none)no line
Output
Use the sprintf function to change the title of the previous plot to Plot of
VariousPolynomials from 5 to 5"
M - File Code
x=linspace(-5,5,20)
hold on
plot(x,x.^2,'ko')
plot(x,x.^3,'r*')
hold off
title(sprintf('Plot of various polynomials for %d to
%d',x(1), x(end)))
xlabel('xaxis')
ylabel('yaxis')
grid on
OutPut
Use the axisfunction to change the limits such that xis visible
from 6 to 6 and yis visible from 10 to 10
M-File
x=linspace(-5,5,100)
hold on
plot(x,x.^2,'ko')
plot(x,x.^3,'r*')
hold off
title(sprintf('Plot of various polynomials for %d to
%d',x(1), x(end)))
xlabel('xaxis')
ylabel('yaxis')
legend('quadratic','cubic')
axis([-6 6 -10 10])
grid on
OutPut
grid on
subplot(2,3,3)
bar(x,y)
title('Bar')
xlabel('X')
ylabel('Y')
grid on
subplot(2,3,4)
loglog(x,y)
title('LogLog')
xlabel('X')
ylabel('Y')
grid on
subplot(2,3,5)
semilogx(x,y)
title('Semilogx')
xlabel('X')
ylabel('Y')
grid on
subplot(2,3,6)
semilogy(x,y)
title('semilogy')
xlabel('x')
ylabel('y')
grid on
OutPut
3D Plotting
M-File Code
t=[0:pi/50:10*pi];
plot3(sin(t),cos(t),t)
grid on
axis square
title('Parametric curve')
xlabel('x')
ylabel('y')
zlabel('t')
OutPut
Make a 1 2 subplot of the surface f (x, y) = sin (x) cos (y) for
5 x 5,5 y 5, the first using the surffunction and the
second using the contourfunction. Take care touse a sufficiently
fine discretization in xand yto make the plot look smooth.
M-File Code
x=-5:.2:5;
y=-5:.2:5;
[X,Y]=meshgrid(x,y);
z=sin(X).*cos(Y);
subplot(1,2,1)
surf(x,y,z)
title('Surface plot using Surf')
xlabel('x')
ylabel('y')
zlabel('z')
subplot('1,2,2')
contour(x,y,z)
title('Surface plot using contour')
xlabel('x')
ylabel('y')
OutPut
Fplot
1.Bar Plot
M file Code
>> x=[1:5];
>> y=[50,98,75,80,98];
>> bar(x,y),xlabel('student'),ylabel('score')
>> bar(x,y),xlabel('student'),ylabel('score');
>> bar(x,y),xlabel('student'),ylabel('score'),title('Final Exam')
OutPut
2.Stem Plot
M-File Code
>> t=[0:5:200];
>> f=exp(-0.01*t).*sin(t/4);
>> stem(t,f),xlabel('time(sec)'),ylabel('spring response');
OutPut
Polar Plot
command window
>> a=2;
>> theta=[0:pi/20:2*pi];
>> r=a*theta;
>> polar(theta,r)
Out Put
2.polar plot
Command window
a=2;
>> theta=[0:pi/90:2*pi];
>>
>> r=1+2*cos(theta);
Output
Contour Plot
Command Window
>> [x,y]=meshgrid(-5:0.1:5,-3:0.1:3);
>> z=x.^2+y.^2;
>> contour(x,y,z)
Output
Contour 3d plot
Command Window
>> [x,y]=meshgrid(-5:0.1:5,-3:0.1:3);
>> z=x.^2+y.^2;
>> contour3(x,y,z)
output
Contour 3d plot
Command Window
>> [x,y]=meshgrid(-5:0.1:5,-3:0.1:3);
>> z=cos(x).*sin(y);
>> contour3(x,y,z)
>>
2.semilogx
Command Window
>> x=0:0.2:100;
>> y=x.^2;
OutPut
3.semilogy
command window
>> x=0:0.2:100;
>> y=x.^2;
>> semilogy(x,y)
output
4.loglog
Command Window
>> x=0:0.2:100;
>> y=x.^2;
output
output
New Command
gtext
command window
>> x=[0:0.1:10];
>> y=x.^3+x.^2+3.*x;
>> plot(x,y),xlabel('X'),ylabel('Y'),title(' gtext comand
checking'),legend('x.^3+x.^2+3.*x'),gtext('pakistan')
output