MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
MuPAD^{®} presents many options for creating and working with
graphics and animations. The simplest way to create a plot in MuPAD is
to use the plot
command.
Using this command, you can:
You can format the plot interactively.
The plot
command
provides a basic way to create function plots. For example, you can:
Create a 2-D function plot using plot::Function2d
.
Create a 3-D function plot using plot::Function3d
.
Create animated plots.
Create turtle graphics
and Lindenmayer systems
.
Choose colors
, fonts, legends, axes appearance, grid lines,
tick marks, line, and marker styles.
Apply affine transformations to a plot. You can scale, rotate, reflect, or move a plot.
Set cameras for a 3-D plot.
See the MuPAD gallery of plots.
To see all functions available in the MuPAD graphics library, enter:
info(plot)
The simple way to create a 2-D plot of a function is to use
the plot
command:
plot(sin(x)*cos(3*x))
The simple way to create a 3-D plot of a function is to use
the plot
command
with the option #3D
:
plot(sin(x)*sin(y), #3D)
Note:
By default, for a function of two variables, the |
To plot several functions in one figure, list all the functions, separating them by commas. MuPAD uses different colors when plotting multiple functions:
plot(sin(x), cos(x), tan(x), cot(x))
You can use the sequence generator $
to create a sequence of functions:
plot(sin(k*x) $ k = 1..3)
You also can plot multiple functions in one 3-D graph:
plot(-sqrt(r^2 - x^2 - y^2) $ r = 1..5, #3D)
You can specify a range over which to plot a function:
plot(sin(x^3)*exp(x), x = 3..5)
plot(sin(x)*sin(y), x = 0..3, y = 1..3, #3D)
For multiple functions plotted in one graph, you can specify one range for all the functions:
plot(sin(k*x) $ k = 1..5, x = 0..2*PI)
To specify different ranges for multiple functions plotted in one graph, use different variables:
plot({sin(k*x), k*t^2} $ k = 1..5, x = 0..2*PI, t = -1..1)
To specify a piecewise function, use the piecewise
command. You can plot a piecewise
function even if it is undefined at some points. for example, you
can plot the following function although the function is not defined
for -2 < x < -1
:
plot(piecewise([x < - 2, - 1], [-1 < x and x < 0, x^2], [0 < x and x < 1, -x^2], [x > 1, 1]))
In MuPAD, you can format your graphic results interactively when working in plot formatting mode. To switch to graphics formatting mode, click any place on a plot. In this mode, the Object Browser pane appears.
If you do not see the Object Browser and Property panes, select View > Object Browser or click on the toolbar.
The top of the Object Browser pane displays the components of your graphics such as scene (background), coordinate system, and a function plot. For further information on the structure of graphics, see The Full Picture: Graphical Trees.
After you select a component in the Object Browser pane, the bottom of the pane displays the properties of this component.
To change background settings of your graphics, switch to plot formatting mode and select Scene at the top of the Object Browser pane. The bottom of the pane shows background properties that you can change. For example, you can change the background color. To choose the color, select BackgroundColor and click the ellipsis button.
You can use predefined colors or select a color from a more extensive palette.
To format the axes of your graphics, switch to plot formatting mode and select Coordinate System at the top of the Object Browser pane. The bottom of the pane shows axes properties that you can change. For example, you can add grid lines.
To format the function plot, switch to plot formatting mode and select Function at the top of the Object Browser pane. The bottom of the pane shows plot properties that you can change. For example, you can change the color of a function plot.
You can use predefined colors or select a color from a more extensive palette.
When you present graphic results in MuPAD, you can move, zoom, and rotate your graphics. You also can select different components of a plot. When presenting graphic results, switch to the plot formatting mode. You can use the following toolbar to manually rotate, move, zoom your plot, and show coordinates of any point on your plot:
To see the coordinates for a point on your plot, click the point and hold the mouse button. You can move the cursor while holding the mouse button and see the coordinates of all the points on the path of the cursor.
You can use the toolbar to rotate and zoom your plot automatically. You also can change the speed for rotation and zooming.
To create an animated plot, use an additional changing parameter
for the function you want to plot. Specify the range for this parameter.
The following example presents an animated plot of a function with
the parameter a
that gradually changes value from
2 to 6:
plot(exp(x)*sin(a^2*x), x = 1..2, a = 2..6)
To create an animated 3-D plot, use an additional changing parameter
for the function you want to plot. Specify the range for this parameter
and the option #3D
. The following example presents
an animated plot of a function with the parameter a
that
gradually changes value from 0.1 to 2:
plot(sin(a*x^2 + a*y^2), x = -2..2, y = -2..2, a = 0.1..2, #3D)
MuPAD displays the first frame of an animation as static picture. To play the animation, click the picture.
When MuPAD plays an animation, the Animation toolbar with the player controls appears:
To play an animation forward and then backward, click the Repetition button and select the option Back and Forth.
You also can specify the range for a parameter so that the initial
value is greater than the final value. The following example creates
an animated plot of the function using the parameter a
that
gradually changes value from 2 to 0.1:
plot(sin(a*x^2 + a*y^2), x = -2..2, y = -2..2, a = 2..0.1, #3D)