Matlab Lect 11
Matlab Lect 11
Lecture 11
CARTESIAN COORDINATE SYSTEM
EXAMPLE
MATLAB - PLOTTING
x = [0:5:100];
y = x;
plot(x, y)
x = [1 2 3 4 5 6 7 8 9 10];
x = [-100:20:100];
y = x.^2;
plot(x, y)
MATLAB - PLOTTING
9;
g = 5 * x.^3 + 9 * x + 2;
x = 1900:10:2000;
y = [75 91 105 123.5 131 150 179 203 226 249 281.5];
bar(x,y)
Y = [5,2,1
8,7,3
9,8,6
5,5,5
4,3,2];
bar(Y)
bar(Y,'stacked')
bar(Y,'g')
bar(y,'FaceColor',[0 .3 .2],'EdgeColor',[0 .7 .7],'LineWidth',1.8)
HISTOGRAMS
plot(X,Y,LineSpec)
plot(X1,Y1,...,Xn,Yn)
plot(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn)
plot(Y)
plot(Y,LineSpec)
EXAMPLE
x = linspace(0, 4 * pi, 500);
y = sin(x) .* cos(2 * x);
plot(x, y);
----------------
x=linespace(-2*pi,2*pi,100)
y1=sin(x);
y2=cos(x);
figure
plot(x,y1,x,y2
-----------------
Y = magic(4)
figure
plot(Y)
3D PLOTS
Types of 3D Plots
Surface Plots − These visualize functions of
plot3(X,Y,Z,LineSpec)
plot3(X1,Y1,Z1,...,Xn,Yn,Zn)
plot3(X1,Y1,Z1,LineSpec1,...,Xn,Yn,Zn,LineSpec
n)
3D PLOT
x=r.cos(t)
y=r.sin(t)
z=h.t
----------------------
r = 1;
h = 1;
t = 0:0.1:10*pi; r = 1; % Radius
h = 1; % Pitch
x = r * cos(t); t = 0:0.1:10*pi;
y = r * sin(t); x = r * cos(t);
y = r * sin(t);
z = h * t; z = h * t;
plot3(x, y, z); plot3(x, y, z, 'o');
---------------
3D
x = linspace(-2,2,20);
y = x';
z = x .* exp(-x.^2 - y.^2);
surf(x,y,z)
MULTIPLE PLOTS
t = tiledlayout(2,2);
title(t,"Trigonometric Functions")
x = linspace(0,30);
nexttile
plot(x,sin(x))
title("Sine")
nexttile
plot(x,cos(x))
title("Cosine")
nexttile
plot(x,tan(x))
title("Tangent")
nexttile
plot(x,sec(x))
title("Secant")
t = 0:pi/50:10*pi;
st = sin(t);
ct = cos(t);
plot3(st,ct,t)
t = 0:pi/500:pi;
xt1 = sin(t).*cos(10*t);
yt1 = sin(t).*sin(10*t);
zt1 = cos(t);
xt2 = sin(t).*cos(12*t);
yt2 = sin(t).*sin(12*t);
zt2 = cos(t);
t = 0:pi/500:40*pi;
xt = (3 + cos(sqrt(32)*t)).*cos(t);
yt = sin(sqrt(32) * t);
zt = (3 + cos(sqrt(32)*t)).*sin(t);
plot3(xt,yt,zt)
axis equal
xlabel('x(t)')
ylabel('y(t)')
zlabel('z(t)')
PLOT A 3D CONTOUR