Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: MATLAB- 2D 3D Plots BASICS
Description: In this pdf, you will learn all the 2D-3D Plots code in Matlab. You will get to know about all the basic commands used in Matlab. There are solved examples too.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


MATLAB
2D and 3D PLOTS

MATLAB PLOTTING

Creating Vectors
Create vector with equally spaced intervals

>> x=0:0
...
5000 1
...
5000 2
...
5000 3
...
5236 1
...
5708 2
...
6180 3
...
0000 14
...
5443 … 68
...
0000

Note: The logspace creates 7 equally distributed values between

101

and 10

2

Initial
Value

100

Length of the
increment

90

Final value

80
70
60
50
40

>> x=[0:5:100];
>> y=x;
>> plot(x,y)
>> stem(x,y)

30
20
10
0

0

10

20

30

40

50

60

70

80

90

100

90

100

100
90
80
70
60
50
40

NOTE: stem( ) is used to plot
discrete sequence data
...


>>y=x
...
8
0
...
4
0
...
^3;
>> plot(x,y)
>> stem(x,y)

-0
...
4
-0
...
8
-1
-100

-80

-60

-40

-80

-60

-40

-20

0

20

40

60

80

100

6

1

x 10

0
...
6
0
...
2

NOTE:
If the length of the increments
are small, then curve will be
more smoother
...
2
-0
...
6
-0
...
of increments
1
0
...
6

>> x=linspace(0,4*pi,100);
>> y=sin(x);
>> plot(y);

0
...
2
0
-0
...
4
-0
...
8
-1

0

10

20

30

40

50

60

70

80

90

100

2D PLOTS
To Plot the function e(-x/3) between 0≤x≤4π
1
0
...
8
0
...
6
0
...
4
0
...
2
0
...
8

>> a=linspace(0,4*pi,100);
>> b=cos(a);
>> plot(a,b);

0
...
4
0
...
2
-0
...
6
-0
...
7
0
...
5
0
...

>>y3=y1
...
3
0
...
1
0
-0
...
2
-0
...
7
0
...
5
0
...
3
0
...
1
0
-0
...
2
-0
...
8
0
...
4

f(x)-values

x=linspace(0,2*pi,100);
y=sin(x);
plot(x,y);
title('this is sinus function');
xlabel('x-values');
ylabel('f(x)-values');

0
...
2
-0
...
6
-0
...
8
0
...
4
0
...
2
-0
...
6
-0
...
8
0
...
4
0
...
2
-0
...
6
-0
...
5

0
...
5

-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
...
5

0
...
5

-0
...
5

0
...
5

0

0

2

4

6

8

-1

0

2

4

COLOR PLOTS

2D PLOTS
To plot with color and special symbols

2D PLOTS

2D PLOTS
To plot with color and special symbols
100
80
60

x = (-pi/2)+0
...
01:(pi/2)-0
...
5

-1

-0
...
5

1

1
...
01:pi;
plot(x,cos(x),'y-*');
title('This is cosine
function');
grid on

0
...
6
0
...
2
0
-0
...
4
-0
...
8
-1
-4

-3

-2

-1

0

1

2

3

4

2D PLOTS
To draw a circle with centre (1, 3)
Circle
5
4
...
5

y-axis

clc
clear all
t = linspace(0, 2*pi, 101);
x = 1 +2*cos(t);
y = 3 +2*sin(t);
plot(x,y,'r
...
5
2
1
...
5

-1

-0
...
5

1
x-axis

1
...
5

3

3
...
8

0
...
2
y axis

y = linspace(-10,10,1000)
plot(y,cos(y),'b
...
')
xlabel('x axis')
ylabel('y axis')
legend('cos(x)','cos(2x)‘)

0
...
2
-0
...
6
-0
...
1:5,-3:0
...
^2 + y
...
1:5,-3:0
...
^2 + y
...


You can change the domain by adding a second argument
to the call to ezplot
...
2

2
...
6

2
...
2

3
...
6

3
...

x 3 - 27 x
-40
-42
-44
-46

y=x^3-27*x;
ezplot(y,[2,4])
ylim([-60,-40])

-48
-50
-52
-54
-56
-58
-60

2

2
...
4

2
...
8

3
x

3
...
4

3
...
8

4

Note that you don’t have to define y first to use ezplot;
you can just type in the function you want to graph:
cos(2 x) cos(x)
1
0
...
6
0
...
2
0
-0
...
4
-0
...
8
-1
-6

-4

-2

0
x

2

4

6

POLAR PLOTS
90

1

120

60
0
...
6

150

30
0
...
2
180

0

210

330

240

300
270
r = cos(2 )

3D PLOTS
t=linspace(0,2*pi,500);
x=cos(t);
y=sin(t);
z=sin(5*t);
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
title('3D Curve');
comet3(x,y,z);
plot3(x,y,z);

Curves in space
You can use the ”ezplot3” function to graph curves in
space
...
5

1
0
...
5
y

-0
...
2:2);
g = x
...
^2 - y
...
5

0

-0
...
05:1;
y=-1:
...
*y
...
^3
surf(x,y,z);
colormap spring
shading interp

1

0
...
5

-1
1
0
...
5

0

0

-0
...
5
-1

-1

3D PLOTS
2 x2 + 2 y2

syms x y
f = 2*(x^2+y^2)
ezsurf(f)
colormap cool

150

100

50

0
5
5
0

0
-5

y

-5
x

3D PLOTS

x 2+y 2

200

150

100

50

0
10

>> ezsurf('x^2+y^2',[10 10 -10 10])
>> ezsurf('x^2+y^2',[10 10 -10 10],'circ')

5

10
5

0

0

-5

-5
-10

y

-10

x

x 2+y 2

250
200

z

150
100
50
0
20
10

20
10

0

0

-10
y

-10
-20

-20

x

SAVE PLOTS


Title: MATLAB- 2D 3D Plots BASICS
Description: In this pdf, you will learn all the 2D-3D Plots code in Matlab. You will get to know about all the basic commands used in Matlab. There are solved examples too.