如何使用 mathematica 绘制斜率场?

发布于 2024-12-27 14:24:46 字数 285 浏览 4 评论 0原文

我正在尝试使用 mathematica 绘制一些微分方程的斜率场,但无法弄清楚。假设我有方程

    y' = y(t) 
    y(t) = C * E^t

如何绘制斜率场?

我找到了一个例子,但对我来说理解起来很复杂 http://demonstrations.wolfram.com/SlopeFields/

I am trying to plot slope fields of some differential equations using mathematica but can't figure it out. Say I have the equation

    y' = y(t) 
    y(t) = C * E^t

How do I plot the slope field?

I found an example but way to complex for me to understand
http://demonstrations.wolfram.com/SlopeFields/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵情客 2025-01-03 14:24:46

您需要的命令(自版本 7 起)是 VectorPlot。文档中有很好的示例。

我认为您感兴趣的情况是一个微分方程

y'[x] == f[x, y[x]]

在您在问题中给出的情况下,

f[x_, y_] := y

它积分为指数

In[]:= sol = DSolve[y'[x] == f[x, y[x]], y, x]
Out[]= {{y -> Function[{x}, E^x c]}}

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

VectorPlot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 2}]

y

东西用 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]]

这可以使用类似y Again

也许更有趣的例子是高斯

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]]

-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]}

正弦[xy]

The command you need (since version 7) is VectorPlot. There are good examples in the documentation.

I think the case that you're interested in is a differential equation

y'[x] == f[x, y[x]]

In the case you gave in your question,

f[x_, y_] := y

Which integrates to the exponential

In[]:= sol = DSolve[y'[x] == f[x, y[x]], y, x]
Out[]= {{y -> Function[{x}, E^x c]}}

We can plot the slope field
(see wikibooks:ODE:Graphing) using

VectorPlot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 2}]

y

This can be plotted with the solutions to the DE using something like

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]]

y again

Maybe a more interesting example is the Gaussian

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]]

-xy


Finally, there is a related concept of the gradient field, where you look at the gradient (vector derivative) of a function:

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]}

Sin[x y]

纵性 2025-01-03 14:24:46

从您链接的演示中可以看出,它需要一个函数 f(x,y) 但您有一组微分。但是,知道 f(x,y)=y(x)',您可以只使用 f(x,y)=C*E^x 其中x=t。我的差速器可能有点生锈,但我很确定这是对的。

It would appear from the demonstration you linked that it takes a function f(x,y) but you have a set of differentials. However, knowing that f(x,y)=y(x)', you could just use f(x,y)=C*E^x where x=t. My Differentials might be a little rusty, but I'm pretty sure that's right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文