Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lists of Equations

0 views
Skip to first unread message

Michael Knudsen

unread,
Jan 8, 2010, 4:13:33 AM1/8/10
to
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

dh

unread,
Jan 8, 2010, 6:28:53 AM1/8/10
to

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

Albert Retey

unread,
Jan 8, 2010, 6:29:26 AM1/8/10
to
Am 08.01.2010 10:13, schrieb Michael Knudsen:
> 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.

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

David Park

unread,
Jan 10, 2010, 3:29:56 AM1/10/10
to
Michael,

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

Bob Hanlon

unread,
Jan 10, 2010, 3:30:08 AM1/10/10
to

It is generally more convenient to use the form z[1][x] rather than z1[x]

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


0 new messages