将向量方程转换为 Mathematica 中的方程列表
由于 DSolve 语法,微分方程组必须以方程列表的形式给出,而不是以向量方程的形式给出(与 Solve 不同,Solve 接受两者)。 所以我的简单问题是如何转换矢量方程,例如:
{f'[t],g'[t]}=={{a,b},{c,d}}.{f[t],g[t]}
到方程列表:
{f'[t]==a*f[t]+b*g[t],g'[t]==c*f[t]+d*g[t]}
我想我曾经知道答案,但我现在找不到它,我认为它也可以使其他人受益。
Due to DSolve syntax, systems of differential equations have to be given as lists of equations and not as a vector equation (Unlike Solve, which accepts both).
So my simple question is how to convert a vector equation such as:
{f'[t],g'[t]}=={{a,b},{c,d}}.{f[t],g[t]}
To list of equations:
{f'[t]==a*f[t]+b*g[t],g'[t]==c*f[t]+d*g[t]}
I think I knew once the answer, but I can't find it now and I think it could benefit others as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 Thread:
它采用相等运算符
==
并将其应用于具有相同Head
的列表中的每个项目。Try using Thread:
It takes the equality operator
==
and applies it to each item within a list with the sameHead
.这个问题的标准答案是 Brett 提出的,
即,使用
Thread
。但是,我发现在
DSolve
、NDSolve
等中使用...命令LogicalExpand
更好。它不会将向量方程转换为列表,但它更有用,因为它会自动展平矩阵/张量方程以及向量方程的组合。
例如,如果你想在上面的微分方程中添加初始条件,你可以使用
矩阵方程的一个例子是
Thread
这里很尴尬,你需要多次应用它压平
结果。使用LogicalExpand
很简单The standard answer to this question is that which Brett presented,
i.e., using
Thread
.However, I find that for use in
DSolve
,NDSolve
, etc... the commandLogicalExpand
is better.It doesn't convert a vector equation to a list, but it is more useful since it automatically flattens out matrix/tensor equations and combinations of vector equations.
For example, if you wanted to add initial conditions to the above differential equation, you'd use
An example of a matrix equation is
Using
Thread
here is awkward, you need to apply it multiple times andFlatten
the result. UsingLogicalExpand
is easy