主要内容

创建图

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创建符号表达式的2-D图,笛卡尔坐标中的方程式或函数。

  • fplot3to create 3-D parametric plots.

  • ezpolarto create plots in polar coordinates.

  • fsurfto create surface plots.

  • fcontourto create contour plots.

  • fmesh创建网格图。

绘制符号表达式 sin ( 6 x ) 通过使用fplot。By default,fplot使用范围 - 5 < x < 5

symsxfplot(sin(6*x))

图包含一个轴对象。轴对象包含一个类型函数线的对象。

在极坐标中绘制符号表达或功能 r (半径)和 θ (极角)通过使用ezpolar。By default,ezpolarplots a symbolic expression or function over the interval 0 < θ < 2 π

绘制符号表达式 sin ( 6 t ) 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 expressionsuv, substitute the symbolic variablesxywith 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 plotUV通过使用标准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 f = e x sin ( 2 0 x ) usingfplot。显示 f by superimposing plots of e x - e x 当红色线条。通过使用显示名称property of the object returned byfplot

symsxyf = exp(x)*sin(20*x)
f =
                  
                   
                    
                     
                      
                       
                        
                         sin
                       
                       
                        
                         (
                        
                         
                          
                           
                            
                             20
                            
                            
                            
                             x
                           
                          
                         
                        
                        
                         )
                       
                      
                      
                      
                      
                       
                        
                         e
                       
                       
                        
                         x
                       
                      
                     
                    
                   
                  
obj = fplot(f,[0 3]); holdfplot(exp(x), [0 3],“——r”) fplot(-exp(x), [0 3],“——r”) title(obj.DisplayName) hold离开

图包含一个轴对象。这axes object with title s i n ( 2 0 blank x ) blank e x p ( x ) contains 3 objects of type functionline.

在一个图中绘制多个符号函数

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 ambyn子图的矩阵并选择子图p。通过选择子图和使用绘图命令,在单独的子图中显示多个图。绘制到多个子图可用于并排比较图。

比较图 s i n ( ( x 2 + y 2 ) / a ) for a = 1 0 , 2 0 , 5 0 , 1 0 0 通过使用子图创建并排子图。

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')

图包含4个轴对象。带标题a = 10的轴对象1包含一个functionsUrface的对象。带标题a = 20的轴对象2包含一个functionSurface的对象。带标题a = 50的轴对象3包含一个functionSurface的对象。带标题a = 100的轴对象4包含一个functionSurface的对象。

结合符号函数图和数字数据图

Plot numeric and symbolic data on the same graph by using MATLAB and Symbolic Math Toolbox functions together.

For numeric values of x between [ - 5 , 5 ] , return a noisy sine curve by finding y = sin ( x ) 和adding random values to y 。通过使用来查看嘈杂的正弦曲线分散to plot the points ( x 1 , y 1 ) , ( x 2 , y 2 ) ,

x = linspace(-5,5); y = sin(x) + (-1).^randi(10, 1, 100).*rand(1, 100)./2; scatter(x, y)

图包含一个轴对象。这axes object contains an object of type scatter.

Show the underlying structure in the points by superimposing a plot of the sine function. First, use坚持,稍等保留散点图。然后,使用fplot绘制正弦函数。

holdsymstfplot(sin(t)) hold离开

图包含一个轴对象。轴对象包含2个类型散点,函数线的对象。

将数字和符号图组合在3-D中

通过使用MATLAB和符号数学工具箱绘图函数,将符号图和数字图组合在3-D中。符号数学工具箱提供以下3D绘图功能:

  • fplot3创建3-D参数化线图。

  • fsurfcreates 3-D surface plots.

  • fmeshcreates 3-D mesh plots.

通过使用fplot3to plot the parametric line

x = ( 1 - t ) sin ( 1 0 0 t ) y = ( 1 - t ) cos ( 1 0 0 t ) z = 1 - x 2 - y 2

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参数线')

图包含一个轴对象。这axes object with title Symbolic 3-D Parametric Line contains an object of type parameterizedfunctionline.

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') 抓住离开

图包含一个轴对象。带有标题符号参数图的轴对象和一个球体包含2个类型的参数式功能线的对象,Surface。