0% found this document useful (0 votes)
16 views

Matlab 2

The document discusses plotting various graphs and curves using MATLAB. It includes examples of plotting simple graphs, sinusoidal graphs, a circle, 3D curves, using subplots and meshgrids. It also includes practice problems for the reader to try plotting different functions.

Uploaded by

lazzygirl2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Matlab 2

The document discusses plotting various graphs and curves using MATLAB. It includes examples of plotting simple graphs, sinusoidal graphs, a circle, 3D curves, using subplots and meshgrids. It also includes practice problems for the reader to try plotting different functions.

Uploaded by

lazzygirl2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

ANOUSKA ACHARYA

20BCE1629

PLOTTING OF CURVES AND GRAPHS

1. Plot graph x=y

x= 0:2:10

x =

0 2 4 6 8 10

x= linspace(0, 3, 5)

x =

0 0.7500 1.5000 2.2500 3.0000

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

Draw a circle with centre(1,3) and radius 2

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

Q4 Draw the graph without hold on function


clc
clear all
y= linspace(-10, 10, 1000);
plot(y, cos(y),'b.',y,cos(2*y),'g.')
xlabel('x-axis')
ylabel('y-axis')
legend('cos(x)','cos(2x)','location','northeast')

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

1. Draw the curve sin(x), cos(x), e-1, x+1 by 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(1)-x,'g.');
title('e-1')
subplot(2,2,4);
plot(x,x+1,'m-o');
title ('x+1')

Figure

2. Draw the curve cos(4x), sin(5x) by using hold on and without hold on functions.

Without hold on:-


clc
clear all
y= linspace(-10,10,1000)
plot(y,cos(4*y),'b.',y,sin(5*y),'g.')
xlabel('x-axis')
ylabel('y-axis')
legend('cos(4x)','sin(5x)','location','northeast')

With hold on:-


clc
clear all
y= linspace(-10,10,1000)
plot(y,cos(4*y),'b.')
hold on
plot(y,sin(5*y),'g.')
xlabel('x-axis')
ylabel('y-axis')
legend('cos(4x)','sin(5x)','location','northeast')
hold off

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

4. Draw the surface x*y^3-y*x^3

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

You might also like