绘制微分方程的解曲线
我有一些微分方程,我想为它们绘制解,对于各种起始值 N_0
以下是方程:
dN\dt= bN^2 - aN
dN\dt = bN^2 (1 - N\K) - aN
我将如何解决?
我不太关心使用的语言。在专门的数学方面,我的计算机上有mathematica 和matlab。我可以访问枫树了。我必须做更多这样的事情,并且我想要任何语言的示例,因为它将帮助我找出我想要使用并学习哪一种语言。
I have a few differential equations that I'd like to draw solutions for, for a variety of start values N_0
Here are the equations:
dN\dt= bN^2 - aN
dN\dt = bN^2 (1 - N\K) - aN
How would I go about it?
I don't really care about the language is used. In terms of dedicated math I have mathematica and matlab on my computer. I've got access to maple. I have to do more of this stuff, and I'd like to have examples from any language, as it'll help me figure out which one I want to use and learn it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会假装第一个问题无法通过分析来解决,以便展示如何在数学中使用一般的常微分方程。
定义
返回 ODE 的解,即
a = p1[.1, 2., 3.]
,然后例如a[.3]
告诉您n(.3)
。然后,可以执行类似的操作,绘制一些具有不同初始值的解决方案:
或者,获得一些见解在解决方案中,我们可以交互地操作
a
、b
和n0
的值:这给出了类似
控件处于活动状态(即移动它们并且绘图发生变化;实时尝试看看我的意思;注意您可以设置初始条件给出不同解决方案的参数)。
当然,这可以任意变得更复杂。此外,在这种特殊情况下,该 ODE 很容易进行分析积分,但该数值方法可以应用于通用 ODE(以及许多偏微分方程)。
I'll pretend the first one cannot be solved analytically so as to show how one would go about playing with a general ODE in mathematica.
Define
which returns the solution of the ODE, i.e.,
a = p1[.1, 2., 3.]
and then e.g.a[.3]
tells youn(.3)
. One can then do something likewhich plots a few solutions with different initial values:
or, to gain some insight into the solutions, one can interactively manipulate the values of
a
,b
andn0
:which gives something like
with the controls active (i.e. you move them and the plot changes; try it live to see what I mean; note that you can set parameters for which the initial conditions gives diverging solutions).
Of course this can be made arbitrarily more complicated. Also in this particular case this ODE is easy enough to integrate analytically, but this numerical approach can be applied to generic ODEs (and many PDEs, too).
除了几个好的答案之外,如果您只是想快速了解 ODE 对于许多起始值的解决方案,作为指导,您始终可以执行一行
StreamPlot
。假设a==1
和b==1
,以及dy/dx == x^2 - x
。StreamStyle -> “Line”
只会给你线条,没有箭头。Adding to the several good answers, if you just want a quick sketch of an ODE's solutions for many starting values, for guidance, you can always do a one-line
StreamPlot
. Supposea==1
andb==1
, anddy/dx == x^2 - x
.StreamStyle -> "Line"
will give you just lines, no arrows.在Mathematica中,你使用 NDSolve (除非它可以解析求解,在这种情况下你使用 DSolve。所以对于你的第一个方程,我尝试过:
我不知道 a、b 或 N0 使用什么,但我得到了这个结果:
In Mathematica you use NDSolve (unless it can be solved analytically, in which case you use DSolve. So for your first equation I tried:
I didn't know what to use for a, b or N0, but I got this result:
如果您愿意以数值方式求解方程,
MATLAB
有一组可能有用的 ODE 求解器。 此处ode45 函数的文档>。一般方法是定义一个描述微分方程右侧的“ode 函数”。然后,您可以将此函数以及初始条件和积分范围传递给
ode
求解器。这种方法的一个吸引人的特点是它可以直接扩展到耦合 ODE 的复杂系统。
希望这有帮助。
If you're happy to solve the equations numerically,
MATLAB
has a set of ODE solvers that might be useful. Check out the documentation for theode45
function here.The general approach is to define an "ode function" that describes the right-hand-side of the differential equations. You then pass this function, along with initial conditions and an integration range to the
ode
solvers.One attractive feature of this type of approach is that it extends in a straight-forward way to complex systems of coupled ODE's.
Hope this helps.