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

[mg21979] multiple subscripted variables in NDSolve; dsfun

36 views
Skip to first unread message

Hartmut Wolf

unread,
Feb 10, 2000, 3:00:00 AM2/10/00
to
stephen e. schwartz schrieb:
>

> I am attempting to use NDSolve (Mathematica 4.0.1.0, mac) to solve a set of coupled
> ODEs in the time variable t. Initially I had a set of variables a[i][t],
> which solve just fine. The index [i] ranges {1, nc}
>
> Then I wanted to add another set of variables mn[i][t]. Attempts to solve
> the set (it is still a set of ODEs) brings the response:
>
> NDSolve::dsfun: "{a[1][t], mn[1][t]} cannot be used as a function"
>
> I had defined the argument of NDSolve as a table,
>
> NDSolve[{eq, ic}, Table[{a[i][t], mn[i][t]}, {i, nc}] where eq, ic are
> tables of equations and initial conditions, resp.
>
> If I "fool" Mathematica by renaming the variable mn[i] as a[i + nc] and suitably
> modify my equations and initial conditions, and the range if the index, the
> set solves just fine, although I am very unhappy about the notation in that
> a and mn represent very different variables.
>
> So, am I correct in inferring that the compact notation for a set of
> coupled indexed equations (Mathematica book, 4th ed, sec 3.9.7, page 926) works
> only for a single variable name?
>
> Is there a more elegant fix?
>

Dear Stephen,

if you rework the example in sec. 3.5.10 of The Mathematica Book

In[1]:= DSolve[{y[x] == -z'[x], z[x] == -y'[x]}, {y, z}, x]

to your manner of denoting the variables

In[2]:=
DSolve[{a[1][t] == -mn[1]'[t], mn[1][t] == -a[1]'[t]}, {a[1], mn[1]}, t]

you'll see it isn't that. Instead you introduced Table

In[3]:=
DSolve[{a[1][t] == -mn[1]'[t], mn[1][t] == -a[1]'[t]},
Table[{a[i], mn[i]}, {i, 1}], t]

and it stops working -- because now you no longer have a flat list of
variables.
So

In[4]:=
DSolve[{a[1][t] == -mn[1]'[t], mn[1][t] == -a[1]'[t]},
Flatten[Table[{a[i], mn[i]}, {i, 1}]], t]


Kind regards, Hartmut


stephen e. schwartz

unread,
Feb 10, 2000, 3:00:00 AM2/10/00
to
Hello Hartmut, you correctly identified the problem. Thank you! I
flattened the tables in my lists of initial conditiions, equations, and
arguments of NDSolve and voila.

My faith is restored.

-steve


At 10:00 AM +0100 2/8/00, Hartmut Wolf wrote:
>stephen e. schwartz schrieb:
>>
>
>> I am attempting to use NDSolve (Mathematica 4.0.1.0, mac) to solve a set
>>of coupled
>> ODEs in the time variable t. Initially I had a set of variables a[i][t],
>> which solve just fine. The index [i] ranges {1, nc}
>>
>> Then I wanted to add another set of variables mn[i][t]. Attempts to solve
>> the set (it is still a set of ODEs) brings the response:
>>
>> NDSolve::dsfun: "{a[1][t], mn[1][t]} cannot be used as a function"
>>
>> I had defined the argument of NDSolve as a table,
>>
>> NDSolve[{eq, ic}, Table[{a[i][t], mn[i][t]}, {i, nc}] where eq, ic are
>> tables of equations and initial conditions, resp.
>>
>> If I "fool" Mathematica by renaming the variable mn[i] as a[i + nc] and
>>suitably
>> modify my equations and initial conditions, and the range if the index, the
>> set solves just fine, although I am very unhappy about the notation in that
>> a and mn represent very different variables.
>>
>> So, am I correct in inferring that the compact notation for a set of
>> coupled indexed equations (Mathematica book, 4th ed, sec 3.9.7, page
>>926) works
>> only for a single variable name?
>>
>> Is there a more elegant fix?
>>
>
>Dear Stephen,
>

>if you rework the example in §3.5.10 of The Mathematica Book


>
>In[1]:= DSolve[{y[x] == -z'[x], z[x] == -y'[x]}, {y, z}, x]
>
>to your manner of denoting the variables
>
>In[2]:=
>DSolve[{a[1][t] == -mn[1]'[t], mn[1][t] == -a[1]'[t]}, {a[1], mn[1]}, t]
>
>you'll see it isn't that. Instead you introduced Table
>
>In[3]:=
>DSolve[{a[1][t] == -mn[1]'[t], mn[1][t] == -a[1]'[t]},
> Table[{a[i], mn[i]}, {i, 1}], t]
>
>and it stops working -- because now you no longer have a flat list of
>variables.
>So
>
>In[4]:=
>DSolve[{a[1][t] == -mn[1]'[t], mn[1][t] == -a[1]'[t]},
> Flatten[Table[{a[i], mn[i]}, {i, 1}]], t]
>
>
>Kind regards, Hartmut

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PLEASE NOTE NEW AREA CODE: 516 --> 631

Stephen E. Schwartz, Senior Scientist mailto:s...@bnl.gov
Environmental Chemistry Division Phone: (631) 344-3100
Brookhaven National Laboratory Fax: (631) 344-2887
Bldg. 815E (75 Rutherford Dr.) PO Box 5000 Sec'y: (631) 344-3275
Upton NY 11973-5000 ftp://ftp.ecd.bnl.gov//pub/steve

Home Page: http://www.ecd.bnl.gov/steve/schwartz.html
Secretary: Maggie Marsch (mailto:mma...@bnl.gov)

Tropospheric Aerosol Program (TAP) Home Page: http://www.tap.bnl.gov
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


0 new messages