如何使用mathematica绘制坡度场?

use*_*102 9 plot wolfram-mathematica differential-equations

我试图使用mathematica绘制一些微分方程的斜率场,但无法弄清楚.说我有等式

    y' = y(t) 
    y(t) = C * E^t
Run Code Online (Sandbox Code Playgroud)

如何绘制坡度场?

我发现了一个例子,但复杂的方式让我理解 http://demonstrations.wolfram.com/SlopeFields/

Sim*_*mon 17

您需要的命令(从版本7开始)是VectorPlot.文档中有很好的例子.

我认为你感兴趣的是一个微分方程

y'[x] == f[x, y[x]]
Run Code Online (Sandbox Code Playgroud)

在你提出问题的情况下,

f[x_, y_] := y
Run Code Online (Sandbox Code Playgroud)

它集成了指数

In[]:= sol = DSolve[y'[x] == f[x, y[x]], y, x]
Out[]= {{y -> Function[{x}, E^x c]}}
Run Code Online (Sandbox Code Playgroud)

我们可以使用绘制斜率场(参见wikibooks:ODE:Graphing)

VectorPlot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 2}]
Run Code Online (Sandbox Code Playgroud)

ÿ

这可以使用类似的东西用DE的解决方案绘制

Show[VectorPlot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 8}, 
   VectorStyle -> Arrowheads[0.03]],
 Plot[Evaluate[Table[y[x] /. sol, {c, -10, 10, 1}]], {x, -2, 2}, 
   PlotRange -> All]]
Run Code Online (Sandbox Code Playgroud)

再次

也许一个更有趣的例子是高斯

In[]:= f[x_, y_] := -x y

In[]:= sol = DSolve[y'[x] == f[x, y[x]], y, x] /. C[1] -> c
Out[]= {{y -> Function[{x}, E^(-(x^2/2)) c]}}

Show[VectorPlot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 8}, 
  VectorStyle -> Arrowheads[0.026]],
 Plot[Evaluate[Table[y[x] /. sol, {c, -10, 10, 1}]], {x, -2, 2}, 
  PlotRange -> All]]
Run Code Online (Sandbox Code Playgroud)

-xy


最后,有一个梯度场的相关概念,您可以在其中查看函数的渐变(向量导数):

In[]:= f[x_, y_] := Sin[x y]
       D[f[x, y], {{x, y}}]
       VectorPlot[%, {x, -2, 2}, {y, -2, 2}]

Out[]= {y Cos[x y], x Cos[x y]}
Run Code Online (Sandbox Code Playgroud)

仙[XY]