Matlab 2
Matlab 2
20BCE1629
x= 0:2:10
x =
0 2 4 6 8 10
x= linspace(0, 3, 5)
x =
x= 0:1:10;
y=x;
plot(x, y)
Figure
2. Plot graphs of cos(x) and sin(x)
x=0:0.01:10;
y=sin(x);
g=cos(x);
plot(x,y,x,g,'.-')
legend('sin(x)','cos(x)')
Figure
3. CIRCLE
clc
clear all
t = linspace(0,2*pi,101);
x = 1 +2*cos(t);
y = 3 +2*sin(t);
plot(x,y,'r.')
xlabel('x-axis')
ylabel('y-axis')
title('circle')
Figure
Figure
5.Draw the curve by using plot3
clc
clear all
t=linspace(0,2*pi,500);
x=cos(t);
y= sin(t);
z= sin(5*t);
comet3(x,y,z)
plot3(x,y,z,'g*','makersize',7)
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
title('3D Curve')
Figure
6. Using subplots
clc
clear all
x=0:0.1:2*pi;
subplot(2,2,1);
plot(x,sin(x),'b*');
title('sin(x)')
subplot(2,2,2);
plot(x,cos(x),'r-o');
title('cos(x)')
subplot(2,2,3);
plot(x,exp(-x),'g.');
title('exp(-x)')
subplot(2,2,4);
plot(x,sin(3*x),'m-o');
title('sin(3x)')
Figure
7.Using fsurf
clc
clear all
syms x y
f=2*(x^2+y^2)
fsurf(f)
%ezsurf(f)
colormap cool
Figure
8.Using fplot
clc
clear all
syms x
y=x^2 + 2*x-6
fplot(y)
Figure
9.Meshgrid
clc
clear all
x=-1:0.05:1;
y=-1:0.05:1;
x
y
[x,y]=meshgrid(x,y);
z=x.*y.^2-x.^3
surf(x,y,z);
colormap spring
shading interp
Figure
Practice problems
Figure
2. Draw the curve cos(4x), sin(5x) by using hold on and without hold on functions.
Figure
3. Draw the curve x^2 + 3y^2 by using fsurf and using surf
Using fsurf
clc
clear all
syms x y
f= (x^2 +3*y^2)
fsurf(f)
colormap autumn
Figure
Using surf
clc
clear all
x= -1:0.05:1;
y= -1:0.05:1;
[x,y]=meshgrid(x,y);
z= x.^2-3*y.^2
surf(x,y,z);
colormap spring
shading interp
Figure
clc
clear all
x= -1:0.05:1;
y= -1:0.05:1;
[x,y]=meshgrid(x,y);
z= x.*y.^3-y.*x.^3
surf(x,y,z);
colormap spring
shading interp
Figure