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

Matlab Lect 11

The document provides an overview of fundamental concepts in 2D and 3D plotting using MATLAB, including various plotting functions such as plot(), scatter(), bar(), and histogram(). It explains the syntax and applications of these functions, along with examples for creating line plots, surface plots, and multiple plots. Additionally, it covers the creation of 3D contour plots and the use of Cartesian coordinates for visualizing relationships between variables.

Uploaded by

Rahmath Mohammed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Matlab Lect 11

The document provides an overview of fundamental concepts in 2D and 3D plotting using MATLAB, including various plotting functions such as plot(), scatter(), bar(), and histogram(). It explains the syntax and applications of these functions, along with examples for creating line plots, surface plots, and multiple plots. Additionally, it covers the creation of 3D contour plots and the use of Cartesian coordinates for visualizing relationships between variables.

Uploaded by

Rahmath Mohammed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

FUNDAMENTALS OF FUNCTION

PLOTTING (2-D AND 3-D).

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

 x = [-10 : 0.01: 10];


 y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x +

9;
 g = 5 * x.^3 + 9 * x + 2;

 plot(x, y, 'r', x, g, 'g')


MATLAB - PLOT ARRAYS
Basic plotting functions available in matlab are as follows −
•plot() Function − Creates line plots to visualize relationships between
variables or functions.
•scatter() Function − Produces scatter plots ideal for showcasing
individual data points.
•bar() Function − Constructs bar graphs useful for comparing
categorical data.
X = [16, 2, 3,13, 5];
Y = [1, 3, 5, 7, 20];
plot(X, Y);
X = [16, 2, 3,13];
Y = [1, 3, 5, 7];
% Plotting the array using plot()
function
plot(X, Y, '--go', 'LineWidth', 1,
'MarkerSize', 4);
xlabel('X-axis');
ylabel('Y-axis');
title('Array Plotting');
legend('coordinates');
PLOT VECTORS
X = [1, 2, 3];
Y = [1, 1, 1];
U = [2, -1, 3];
V = [3, 1, -2];
quiver(X, Y, U, V, 1.5);
xlabel('X-axis');
ylabel('Y-axis');
title('Arrow Plot with Scaled Lengths');
BAR GRAPH

y = [50, 85, 110, 135, 155, 180, 210, 230,


255, 280, 300];
bar(y)

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

data = randn(1000, 1);


histogram(data);
----------------------------
x = randn(5000,1);
h = histogram(x)
----------------------------
x = randn(5000,1);
nbins = 25;
h = histogram(x,nbins)
---------------------
2D LINE PLOT

 A 2D line plot is a fundamental visualization


tool in MATLAB used to represent
relationships between two variables.
Synatax
 plot(X,Y)

 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

two variables using a surface that represents


the relationship between the variables.
 Mesh Plots − Mesh plots display wireframe

surfaces and are useful for visualizing


functions of two variables on a grid.
 Scatter Plots − In 3D, scatter plots

represent individual data points in three


dimensions, often with different symbols or
colors to denote different properties.
3D PLOTS
Syntax:
 plot3(X,Y,Z)

 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

[X, Y] = meshgrid(-2:0.1:2, -2:0.1:2);


Z = sin(sqrt(X.^2 + Y.^2));
surfc(X, Y, Z);

You might also like