创建图
Plot with Symbolic Plotting Functions
MATLAB®provides many techniques for plotting numerical data. Graphical capabilities of MATLAB include plotting tools, standard plotting functions, graphic manipulation and data exploration tools, and tools for printing and exporting graphics to standard formats. Symbolic Math Toolbox™ expands these graphical capabilities and lets you plot symbolic functions using:
绘制符号表达式
通过使用fplot
。By default,fplot
使用范围
。
symsxfplot(sin(6*x))
在极坐标中绘制符号表达或功能
(半径)和
(极角)通过使用ezpolar
。By default,ezpolar
plots a symbolic expression or function over the interval
。
绘制符号表达式 in polar coordinates.
symstezpolar(sin(6*t))
Plot Functions Numerically
As an alternative to plotting expressions symbolically, you can substitute symbolic variables with numeric values by using潜艇
。这n, you can use these numeric values with plotting functions in MATLAB™.
In the following expressionsu
和v
, substitute the symbolic variablesx
和y
with the numeric values defined by网格格里德
。
symsxyu = sin(x^2 + y^2);v = cos(x*y);[x,y] = meshgrid(-1:.1:1,-1:.1:1);u = subs(u,[x y],{x,y});v = subs(v,[x y],{x,y});
Now, you can plotU
和V
通过使用标准MATLAB绘图函数。
创建由函数定义的向量字段的图U(X,Y)
和v(x,y)
通过使用the MATLAB颤动
function.
Quiver(X,Y,U,V)
Plot Multiple Symbolic Functions in One Graph
Plot several functions on one graph by adding the functions sequentially. After plotting the first function, add successive functions by using the坚持,稍等
命令。这坚持,稍等
command keeps the existing plots. Without the坚持,稍等
command, each new plot replaces any existing plot. After the坚持,稍等
命令,每一个新的应用程序ears on top of existing plots. Switch back to the default behavior of replacing plots by using the坚持下去
命令。
Plot
usingfplot
。显示
by superimposing plots of
和
当红色线条。通过使用显示名称
property of the object returned byfplot
。
symsxyf = exp(x)*sin(20*x)
f =
obj = fplot(f,[0 3]); hold上fplot(exp(x), [0 3],“——r”) fplot(-exp(x), [0 3],“——r”) title(obj.DisplayName) hold离开
在一个图中绘制多个符号函数
Display several functions side-by-side in one figure by dividing the figure window into several subplots using子图
。命令子图(m,n,p)
divides the figure into am
byn
子图的矩阵并选择子图p
。通过选择子图和使用绘图命令,在单独的子图中显示多个图。绘制到多个子图可用于并排比较图。
比较图
for
通过使用子图
创建并排子图。
symsxyaf = sin((x^2 + y^2)/a); subplot(2, 2, 1) fsurf(subs(f, a, 10)) title('a = 10') subplot(2, 2, 2) fsurf(subs(f, a, 20)) title('a = 20') subplot(2, 2, 3) fsurf(subs(f, a, 50)) title('a = 50') subplot(2, 2, 4) fsurf(subs(f, a, 100)) title('a = 100')
结合符号函数图和数字数据图
Plot numeric and symbolic data on the same graph by using MATLAB and Symbolic Math Toolbox functions together.
For numeric values of
between
, return a noisy sine curve by finding
和adding random values to
。通过使用来查看嘈杂的正弦曲线分散
to plot the points
。
x = linspace(-5,5); y = sin(x) + (-1).^randi(10, 1, 100).*rand(1, 100)./2; scatter(x, y)
Show the underlying structure in the points by superimposing a plot of the sine function. First, use坚持,稍等
保留散点图。然后,使用fplot
绘制正弦函数。
hold上symstfplot(sin(t)) hold离开
将数字和符号图组合在3-D中
通过使用MATLAB和符号数学工具箱绘图函数,将符号图和数字图组合在3-D中。符号数学工具箱提供以下3D绘图功能:
通过使用fplot3
to plot the parametric line
symstx = (1-t)*sin(100*t); y = (1-t)*cos(100*t); z = sqrt(1 - x^2 - y^2); fplot3(x, y, z, [0 1]) title('符号3-D参数线')
Superimpose a plot of a sphere with radius 1 and center at (0, 0, 0). Find points on the sphere numerically by using领域
。Plot the sphere by using网
。结果图显示了包裹在顶部半球周围的符号参数线。
hold上[X,Y,Z] = sphere; mesh(X, Y, Z) colormap(gray) title('Symbolic Parametric Plot and a Sphere') 抓住离开