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

5_Advanced Plotting_Class_S2024_P (1)

Uploaded by

JAS PRAJAPATI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

5_Advanced Plotting_Class_S2024_P (1)

Uploaded by

JAS PRAJAPATI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

MATLAB
for Engineering Applications
Fourth Edition

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 1


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Chapter 05

Advanced Plotting

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 2


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Nomenclature for a typical xy plot. Figure 5.1–1

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 3


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Generating a plot
Example: The following MATLAB session plots 𝑦 = 0.4 1.8𝑥 𝑓𝑜𝑟 0 ≤× ≤ 52,
where 𝑦 represents the height of a rocket after launch, in miles, and 𝑥 is the
horizontal (downrange) distance in miles.

x = 0:0.1:52;
y = 0.4*sqrt(1.8*x);
plot(x,y);
xlabel('Distance (miles) ');
ylabel('Height (miles) ');
title('Rocket Height as a Function of Downrange Distance ');

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 4


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The autoscaling feature in MATLAB selects


tick-mark spacing.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 5


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Obtaining a hard copy of the plot.

The plot will appear in the Figure window. You can obtain a hard copy of the plot
in several ways:

1. Use the menu system. Select Print on the File menu in the Figure window.
Answer OK when you are prompted to continue the printing process.
2. Type print at the command line. This command sends the current plot
directly to the printer.
3. Save the plot to a file to be printed later or imported into another application
such as a word processor. You need to know something about graphics file
formats to use this file properly. See the subsection Exporting Figures.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 6


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The grid and axis Commands

The grid command displays gridlines at the tick marks corresponding to the
tick labels. Type grid on to add gridlines; type grid off to stop plotting
gridlines.

You can use the axis command to override the MATLAB selections for the axis
limits. The basic syntax is axis([xmin xmax ymin ymax]). This command
sets the scaling for the x- and y-axes to the minimum and maximum values
indicated.

plot(x,y,"--",'LineWidth',5) % define the line width

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 7


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The plot versus fplot function


Ploting 𝑓 = cos(tan 𝑥 ) − tan(sin 𝑥 ) with the plot command with 0.01
spacing.
𝑓 = cos(tan 𝑥 ) − tan(sin 𝑥 )

x= [1.0:.01:2.0];
y = cos(tan(x) - tan(sin(x)));
plot(x,y)

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 8


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The fplot function 1

The fplot function chooses a small enough spacing to display the function’s full
behavior.
𝑓 = cos(tan 𝑥 ) − tan(sin 𝑥 )

f = @(x) (cos(tan(x)) - tan(sin(x)));


fplot(f,[1 2])

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 9


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Plotting Polynomials with the polyval Function

To plot the polynomial 3×5 + 2×4 − 100×3 + 2×2 −7× + 90 over the range − 6 ≤
× ≤ 6 with a spacing of 0.01, you type

x = -6:0.01:6;
p = [3,2,-100,2,-7,90];
plot(x,polyval(p,x));
xlabel('x');
ylabel('p');
title('Plotting Polynomial');

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 10


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q1- Plot the equation 𝑦 = 0.4 1.8𝑥 𝑓𝑜𝑟 0 ≤ 𝑥 ≤ 35 𝑎𝑛𝑑 0 ≤ 𝑦 ≤ 3.5.

Title = Rocket Height as a Function of Downrange Distance


X axis label= Distance (miles)
Y axis label=Height (miles)
Assume ‘0.01’ as the default increment for all plots

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 11


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q2- Use the fplot command to plot and investigate the function
tan cos 𝑥 − 𝑠𝑖𝑛(𝑡𝑎𝑛 𝑥)
𝑓𝑜𝑟 0 ≤ 𝑥 ≤ 2𝜋. How many values of x are needed to obtain the same plot using the plot
command?
Hint: fplot can be used to count the number of sample points

[x,y] = fplot(f,[0 2*pi]);

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 12


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q2- Use the fplot command to plot and investigate the function
tan cos 𝑥 − 𝑠𝑖𝑛(𝑡𝑎𝑛 𝑥)
𝑓𝑜𝑟 0 ≤ 𝑥 ≤ 2𝜋. How many values of x are needed to obtain the same plot using the plot
command?
Hint: fplot can be used to count the number of sample points

[x,y] = fplot(f,[0 2*pi]);

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 13


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Plotting Functions

Other useful plotting functions are title and gtext. These functions place text
on the plot. Both accept text within parentheses and single quotes, as with the
xlabel function.
The title function places the text at the top of the plot.
The gtext function places the text at the point on the plot where the cursor is
located when you click the left mouse button.

x = 0:0.01:2*pi;
y = sin(x);
plot(x,y),xlabel('x'),ylabel('y'), gtext('sin(x)');
title(‘My Plot')

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 14


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Subplots 1

You can use the subplot command to obtain several smaller “subplots” in the
same figure. The syntax is subplot(m,n,p). This command divides the
Figure window into an array of rectangular panes with m rows and n columns.
The variable p tells MATLAB to place the output of the plot command
following the subplot command into the pth pane.

For example, subplot(3,2,5) creates an array of six panes, three panes


deep and two panes across, and directs the next plot to appear in the fifth pane
(in the bottom-left corner).

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 15


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Application of the subplot command.


The following script file created Figure 5.2 − 1, which shows the plots of the functions
×
y = e−12 sin(10× + 5) for 0 ≤ × ≤ 5 and y = ×3 − 100 for −6 ≤ × ≤ 6.

x = 0:0.01:5;
y = exp(-1.2*x).*sin(10*x+5);
subplot(1,2,1)
plot(x,y),xlabel('x'),ylabel('y')
,axis([0 5 -1 1])
x = -6:0.01:6;
y = abs(x.^3-100);
subplot(1,2,2)
plot(x,y),xlabel('x'),ylabel('y')
,axis([-6 6 0 350])

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 16


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Subplots 2

The following script file created a figure, which shows the plots of the functions
𝑦 = 𝑒 −1.2𝑥 sin(10𝑥 + 5) for 0 ≤ 𝑥 ≤ 5 and 𝑦 = |𝑥 3 − 100| for −6 ≤ 𝑥 ≤ 6.

x = 0:0.01:5;
y = exp(-1.2*x).*sin(10*x+5);
subplot(3,2,2)
plot(x,y),axis([0 5 -1 1])
x = -6:0.01:6;
y = abs(x.^3-100);
subplot(3,2,3)
plot(x,y),axis([-6 6 0 350])
y= x.^2;
subplot(3,2,6)
plot(x,y),axis([-6 6 -5 50])

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 17


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Data Markers and Line Types 1

To plot y versus x with a solid line and u versus v with a dashed line, type
plot(x,y,u,v,‘--’), where the symbols ‘--’ represent a dashed line.

To plot y versus x with asterisks (*) connected with a dotted line, you must
plot the data twice by typing plot(x,y,‘*’,x,y,‘:’).

x=1:1:10;
y=sqrt(x);
plot(x,y,'*',x,y,':')

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 18


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Data Markers and Line Types 2

To plot y versus x with green asterisks () connected with a red dashed line,
you must plot the data twice by typing plot(x,y,‘g*’,x,y,‘r--’).

x=1:1:10;
y=sqrt(x);
plot(x,y, 'g*',x,y, 'r--')

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 19


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Specifiers for data markers, line types,


and colors

Data markers† Line types Colors


Dot (.) . Solid line — Black k
Asterisk (*) * Dashed line –– Blue b
Cross (´) × Dash-dotted line –. Cyan c
Circle (◦) ◦ Dotted line …. Green g
Plus sign (+) + Magenta m
Square ( ) s Red r
Diamond ( ◊ ) d White w
Five-pointed star (w) p Yellow y

†Other data markers are available. Search for “markers” in MATLAB help.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 20


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Labeling Curves and Data


The legend command automatically obtains from the plot the line type used for
each data set and displays a sample of this line type in the legend box next to the
string you selected.

x = 0:0.01:2;
y = sinh(x);z = tanh(x);
plot(x,y,x,z,'r--'),xlabel('x'),...
ylabel('Hyperbolic Sine and Tangent'),
legend('sinh(x)','tanh(x)')

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 21


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Application of the hold command

x=0:.01:2*pi;
y=cos(x);
plot(x,y);
hold
y=sin(x);
plot(x,y);

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 22


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q3- Pick a suitable spacing for 𝑡 = 0: 0.01: 8; 𝑎𝑛𝑑 𝑣 = −8: 0.01: 8; and then use the subplot
command to plot the following functions

𝑧 = 𝑒 −0.5𝑡 cos(20𝑡 − 6) 𝑓𝑜𝑟 0 ≤ 𝑡 ≤ 8


𝑢 = 6 log10 (𝑣 2 + 20) 𝑓𝑜𝑟 − 8 ≤ 𝑣 ≤ 8.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 23


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q4- Plot the following two data sets on the same plot. For each set, x = 0, 1, 2, 3, 4, 5. Use a
different data marker for each set. Connect the markers for the first set with solid lines.
Connect the markers for the second set with dashed lines. Use a legend, and label the plot axes
appropriately. The first set is y = 11, 13, 8, 7, 5, 9. The second set is y = 2, 4, 5, 3, 2, 4.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 24


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Logarithmic Plots 1

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 25


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Logarithmic Plots 4

MATLAB has three commands for generating plots having log scales. The
appropriate command depends on which axis must have a log scale.

1. Use the loglog(x,y) command to have both scales logarithmic.

2. Use the semilogx(x,y) command to have the x scale logarithmic and the
y scale rectilinear.

3. Use the semilogy(x,y) command to have the y scale logarithmic and the
x scale rectilinear.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 26


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Exponential and Power Functions


Plotted on Log Scales

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 27


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Plot with a tick spacing


Plot the function 𝑦 = sin(𝑥) 𝑓𝑜𝑟 0 ≤ 𝑥 ≤ 2𝜋 with a tick spacing of 𝜋/2 on the 𝑥 axis and
0.2 on the y axis.
gca is (Get Current Axes)
x = 0:0.01:2*pi;
y =sin(x);
plot(x,y),set(gca,'XTick',0:pi/2:2*pi,'YTick',-1:.2:1),...
xlabel('x'),ylabel('y'),title('y = Sin(x)')

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 28


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Polarplot Plots
𝒑𝒐𝒍𝒂𝒓𝒑𝒐𝒍𝒂𝒓 𝜽, 𝝆 :plot using polar coordinates , in radians, versus the radius 𝜌.

Obtain a polar plot of 𝑦 = sin(𝑥) 𝑓𝑜𝑟 0 ≤ 𝑥 ≤ 2𝜋.

x = 0:0.01:2*pi;
y = sin(x);
polarplot(x,y), title('Polar
Plot of y = Sin(x)')

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 29


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q5- The spiral of Archimedes is described by the polar coordinates (𝜃, 𝑟), where 𝑟 = 𝑎𝜃.
Obtain a polar plot of this spiral for 0 ≤ 𝜃 ≤ 4𝜋, with the parameter 𝑎 = 2.

polarplot(theta,r) : will produce a plot of a polar coordinates (θ, r), where θ is


the angular coordinate and r is the radial coordinate.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 30


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q6- Plot the function 𝑦 = 8𝑥 3 𝑓𝑜𝑟 − 1 ≤ 𝑥 ≤ 1 with a tick spacing of 0.25 on the 𝑥 axis
and 2 on the y axis.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 31


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Specialized plot commands. Table 5.2-3.

Command Description
bar(x,y) Creates a bar chart of y versus x.
plotyy(x1,y1,x2,y2) Produces a plot with two y-axes, y1 on the left and y2 on
the right.
polar(theta,r,’type’) Produces a polar plot from the polar coordinates theta
and r, using the line type, data marker, and colors
specified in the string type.

stairs(x,y) Produces a stairs plot of y versus x.


stem(x,y) Produces a stem plot of y versus x.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 32


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The errorbar Command

𝒙𝟐
cos 𝒙 ≈ 𝟏 −
𝟐
errorbar(x,y,err) plots y versus x and draws
a vertical error bar at each data point.

x = linspace(0.1, pi, 20);


approx = 1 - x.^2/2;
error = approx - cos(x);
errorbar(x, cos(x), error);

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 33


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Plotting Implicit Functions

MATLAB provides the function fimplicit(f) to plot the implicit function defined by the
equation f(x,y) = 0 over the default interval [−5 5] for x and y. For example, to plot the
hyperbola defined by x² − y² − 1 = 0 over the default interval of [−5 5], you type

>>fimplicit(@(x,y) x.^2 - y.^2 - 1)

If the limits for x are [−2 2] and the limits for y are [−4 4], you would type

>>fimplicit(@(x,y) x.^2 - y.^2 - 1, [-2 2 -4 4])

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 34


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Plotting Implicit Functions


>>fimplicit(@(x,y) x.^2 - y.^2 - 1)

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 35


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The Live Editor 1

A live script is an interactive document that contains output, including graphics, along with
the code that produced them, together in a single interactive environment called the Live
Editor. You can also include formatted text, images, hyperlinks, and equations to produce
an interactive shareable narrative. Live scripts are stored in a file with the extension .mlx.
You can convert the scripts to HTML or PDF files for publication.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 36


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The Live Editor 3

x=0:0.01:6;
p=[3,2,-100,2,-7,90];
plot(x,polyval(p,x)), xlabel ('x'),
ylabel ('p')

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 37


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Three-Dimensional Line Plots

The following program uses the plot3 function to generate the spiral curve.
𝑥 = 𝑒 − 0.05𝑡 sin 𝑡 , 𝑦 = 𝑒 − 0.05𝑡 cos 𝑡 , 𝑧 = 𝑡

t = 0:pi/50:10*pi;
plot3(exp(-0.05*t).*sin(t),exp(-0.05*t).*cos(t),t),
xlabel('x'),ylabel('y'),zlabel('z'),grid

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 38


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

The curve x = e−0.05t sin t, y = e−0.05t cos t, z = t plotted with the


plot3 function

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 39


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Surface Plots
mesh command creates a three-dimensional surface plot that has solid edge colors and
no face

The following session shows how to generate the surface plot of the function
2 2
𝑧 = 𝑥𝑒 −[ 𝑥−𝑦 +𝑦 2 ] for −2 ≤ x ≤ 2 and −2 ≤ y ≤ 2, with a spacing of 0.1.

A mesh is a representation of a larger geometric domain by smaller discrete cells.

[X,Y] = meshgrid(-2:0.1:2);
Z = X.*exp(-((X-Y.^2).^2+Y.^2));
mesh(X,Y,Z),xlabel('x'),ylabel('y'),zlabel('z');

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 40


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

2 2
A plot of the surface 𝑧 = 𝑥𝑒 −[ 𝑥−𝑦 +𝑦 2 ] created with the mesh function.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 41


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Contour plot of the function


The following session generates the contour plot of
2 2
𝑧 = 𝑥𝑒 −[ 𝑥−𝑦 +𝑦 2 ] , for −2 ≤ 𝑥 ≤ 2 and − 2 ≤ 𝑦 ≤ 2,
with a mesh spacing of 0.1.

[X,Y] = meshgrid(-2:0.1:2);
Z = X.*exp(-((X- Y.^2).^2+Y.^2));
contour(X,Y,Z),xlabel('x'),ylabel('y');

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 42


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

2 2
A contour plot of the surface 𝑧 = 𝑥𝑒 −[ 𝑥−𝑦 +𝑦 2 ]

created with the contour function.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 43


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Surface Plots of Implicit Functions


MATLAB provides the function fimplicit3(f) to plot the three-dimensional implicit
function defined by the equation

𝑓(𝑥, 𝑦, 𝑧) = 0 over the default interval [−5 5] for 𝑥, 𝑦, 𝑎𝑛𝑑 𝑧.

You can specify the interval with the syntax 𝑓𝑖𝑚𝑝𝑙𝑖𝑐𝑖𝑡3(𝑓, 𝑖𝑛𝑡𝑒𝑟𝑣𝑎𝑙).

For example, to plot the upper half of the hyperboloid 𝑥 2 + 𝑦 2 − 𝑧 2 = 0 you specify
the interval as for z as [0 5], and for x and y, use the default interval [−5 5], as
follows.
f = @(x,y,z) x.^2 + y.^2 - z.^2;
fimplicit3(f) ;
interval = [-5 5 -5 5 0 5];

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 44


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Surface Plots of Implicit Functions


− 𝑥 2 +𝑦 2
𝑧 = 𝑥𝑒

f = @(x,y,z) x.^2 + y.^2 - z.^2;


subplot(2,1,1);
fimplicit3(f) ;
subplot(2,1,2);
interval = [-5 5 -5 5 0 5];
fimplicit3(f,interval);

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 45


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Other Three-dimensional plotting functions

Function Description
surf(x,y,z) Creates a shaded 3D mesh surface plot.
surfc(x,y,z) Same as surf but draws contours under the
surface.
waterfall(x,y,z) Same as mesh but draws mesh lines in one
direction only.

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 46


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Plots of the surface z = xe−(x2+y2) created with the mesh


function and its variant forms

[X,Y] = meshgrid(-2:0.1:2);
Z = X.*exp(-(X.^2+Y.^2));
subplot(2,2,1);
xlabel('x')
ylabel('y') surf(X,Y,Z) surfc(X,Y,Z)
surf(X,Y,Z)
subplot(2,2,2);
surfc(X,Y,Z)
subplot(2,2,3);
waterfall(X,Y,Z)
subplot(2,2,4);
meshc(X,Y,Z);
waterfall(X,Y,Z) meshc(X,Y,Z);

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 47


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q7- Use plot3 and fplot3 to plot the 3-D line plot described by 𝑥 = sin(𝑡), 𝑦 = cos(𝑡), 𝑧 =
ln(𝑡) for 0 < 𝑡 < 30.
fplot3 Plot 3-D parametric curve
Example: fplot3(@(t) cos(t) ,@(t)myfunc(t),@(t) sqrt(t), [-pi,pi], '--*‘)

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 48


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q8 Use mesh, fmesh, contour, and fcontour to create a surface plot and a contour plot of the
function 𝑧 = (𝑥 − 2)2 +2𝑥𝑦 + 𝑦 2 .

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 49


FACULTY OF ENGINEERING - UNIVERSITY OF WINDSOR

Q9- Use the fimplicit3 function to create a surface plot of the function
𝑥2 − 𝑦2 − 𝑧2 = 0

Numerical Methods and Modeling for Engineering Applications R. Rashidzadeh 50

You might also like