将向量方程转换为 Mathematica 中的方程列表

发布于 2024-10-07 18:02:46 字数 291 浏览 2 评论 0原文

由于 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 技术交流群。

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

发布评论

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

评论(2

記憶穿過時間隧道 2024-10-14 18:02:46

尝试使用 Thread:

Thread[{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] *)

它采用相等运算符 == 并将其应用于具有相同 Head 的列表中的每个项目。

Try using Thread:

Thread[{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] *)

It takes the equality operator == and applies it to each item within a list with the same Head.

凉栀 2024-10-14 18:02:46

这个问题的标准答案是 Brett 提出的,
即,使用Thread
但是,我发现在 DSolveNDSolve 等中使用...命令 LogicalExpand 更好。

eqn = {f'[t], g'[t]} == {{a, b}, {c, d}}.{f[t], g[t]};

LogicalExpand[eqn]

(* f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)

它不会将向量方程转换为列表,但它更有用,因为它会自动展平矩阵/张量方程以及向量方程的组合。
例如,如果你想在上面的微分方程中添加初始条件,你可以使用

init = {f[0], g[0]} == {f0, g0};

LogicalExpand[eqn && init]

(* f[0] == f0 && g[0] == g0 && 
  f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)

矩阵方程的一个例子是

mEqn = Array[a, {2, 2}] == Partition[Range[4], 2];

Thread这里很尴尬,你需要多次应用它压平结果。使用 LogicalExpand 很简单

LogicalExpand[mEqn]

(* a[1, 1] == 1 && a[1, 2] == 2 && a[2, 1] == 3 && a[2, 2] == 4 *)

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 command LogicalExpand is better.

eqn = {f'[t], g'[t]} == {{a, b}, {c, d}}.{f[t], g[t]};

LogicalExpand[eqn]

(* f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)

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

init = {f[0], g[0]} == {f0, g0};

LogicalExpand[eqn && init]

(* f[0] == f0 && g[0] == g0 && 
  f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)

An example of a matrix equation is

mEqn = Array[a, {2, 2}] == Partition[Range[4], 2];

Using Thread here is awkward, you need to apply it multiple times and Flatten the result. Using LogicalExpand is easy

LogicalExpand[mEqn]

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