I have just started using Mathematica, and I wonder what the easiest
way to manage a large set of equations is. I have a bunch of
differential equations
y1'[x] = z1[x]
y2'[x] = z2[x]
...
yn'[x] = zn[x]
and I have grouped them together in a list like
eqs = {y1'[x]==z1[x], ..., yn'[x]==zn[x]}
which fits perfectly as an argument to NDSolve. However, I think that,
at a later point, I may have to use z1,...,zn separately, and I
thought about defining
yeqs = {y1'[x],...,yn'[x]}
zeqs = {z1[x],...,zn[x]}
and them combine them. What I would really like is something like
yeqs + "==" + zeqs
but I can't seem to find any list operation that will do that. Any
help is appreciated.
Thanks,
Michael Knudsen
Hi Michael,
what you are looking for is: Thread:
yeqs = {y1'[x], y2'[x], y3'[x]};
zeqs = {z1[x], z2[x], z3[x]};
Thread[yeqs == zeqs]
Daniel
I think Thread is your friend:
Thread[yeqs==zeqs]
you should also consider to take advantage of the possibility to use
something as y[1] as a variable in NDSolve, which makes the handling of
lists of expressions a lot easier:
lhs = Table[y[i]'[x], {i, 1, 5}]
rhs = Table[z[i][x], {i, 1, 5}]
Thread[lhs == rhs]
hth,
albert
I assume that zn[x] is an expression in x that you know independently? Then
just define them first.
z1[x_]:= ...
z3[x_]:= ... etc.
Then write your eqns statement.
(eqs = {y1'[x]==z1[x], ..., yn'[x]==zn[x]})//Column
where I have laid them out in a column - just for convenience.
If there is a systematic pattern to the zn functions, you could write them
as
z[x_,k_]:= expression of x and k.
or use SubValues:
z[k_][x_]:= ...
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
From: Michael Knudsen [mailto:mickn...@gmail.com]
Hello,
I have just started using Mathematica, and I wonder what the easiest
way to manage a large set of equations is. I have a bunch of
differential equations
y1'[x] = z1[x]
y2'[x] = z2[x]
...
yn'[x] = zn[x]
and I have grouped them together in a list like
eqs = {y1'[x]==z1[x], ..., yn'[x]==zn[x]}
which fits perfectly as an argument to NDSolve. However, I think that,
at a later point, I may have to use z1,...,zn separately, and I
thought about defining
yeqs = {y1'[x],...,yn'[x]}
zeqs = {z1[x],...,zn[x]}
and them combine them. What I would really like is something like
yeqs + "==" + zeqs
but I can't seem to find any list operation that will do that. Any
help is appreciated.
Thanks,
Michael Knudsen
n = 3;
yVar = Array[y, n];
zVar = Array[z, n];
zx = Through[zVar[x]]
{z[1][x], z[2][x], z[3][x]}
which is equivalent to
zx = (#[x] & /@ zVar)
{z[1][x], z[2][x], z[3][x]}
dy = D[Through[yVar[x]], x]
{Derivative[1][y[1]][x], Derivative[1][y[2]][x], Derivative[1][y[3]][x]}
which is equivalent to
dy = (#'[x] & /@ yVar)
{Derivative[1][y[1]][x], Derivative[1][y[2]][x], Derivative[1][y[3]][x]}
eqs = Thread[dy == zx]
{Derivative[1][y[1]][x] == z[1][x], Derivative[1][y[2]][x] == z[2][x],
Derivative[1][y[3]][x] == z[3][x]}
Bob Hanlon
---- Michael Knudsen <mickn...@gmail.com> wrote:
=============
Hello,
I have just started using Mathematica, and I wonder what the easiest
way to manage a large set of equations is. I have a bunch of
differential equations
y1'[x] = z1[x]
y2'[x] = z2[x]
...
yn'[x] = zn[x]
and I have grouped them together in a list like
eqs = {y1'[x]==z1[x], ..., yn'[x]==zn[x]}
which fits perfectly as an argument to NDSolve. However, I think that,
at a later point, I may have to use z1,...,zn separately, and I
thought about defining
yeqs = {y1'[x],...,yn'[x]}
zeqs = {z1[x],...,zn[x]}
and them combine them. What I would really like is something like
yeqs + "==" + zeqs
but I can't seem to find any list operation that will do that. Any
help is appreciated.
Thanks,
Michael Knudsen
--
Bob Hanlon