       Re: More Anomalous Behaviour with Indexed Variables

• To: mathgroup at smc.vnet.net
• Subject: [mg3306] Re: [mg3256] More Anomalous Behaviour with Indexed Variables
• From: jpk at apex.mpe.FTA-Berlin.de (Jens-Peer Kuska)
• Date: Sun, 25 Feb 1996 03:20:17 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```> Now this has cropped up again with NDSolve.  If you
> get a chance, run the following two groups of expressions
> through your version.  Why does the second version fail?
> Is it because NDSolve no longer evaluates the dummy equation
> first? I am using 2.2.1.
>
> (*
>     PARAMETER IS: f
> *)
>     Clear[ f ];
>     calc[ v_Real ] := ( f = v^2; 0 );
>     NDSolve[ {dummy'[t] == calc[p[t]], dummy==0,
>               p'[t] == -p[t] + f, p==0 }, {dummy,p}, {t,0,1} ]
>
> (*
>     PARAMETER IS: f
> *)
>     Clear[ f ];
>     calc[ v_Real ] := ( f = v^2; 0 );
>     NDSolve[ {dummy'[t] == calc[p[t]], dummy==0,
>               p'[t] == -p[t] + f, p==0 }, {dummy,p}, {t,0,1} ]
>
>
> Mark James

Hi Mark,

at first
I think that it is really dangerous to use sutch side
effect, because there is *no* guarantie that NDSolve evaluate
the differential equations in the same order as given. NDSolve
has to do a lot of things bevore it can start with the numerical
solution.

at second
don't talk about efficient solutions, Mathematica is a interpreter
and will be allways 100 or more times slower than a compiled
code. You can still using Mathematica via MathLink for dawing and post processing.

You mix up in Your code assignet function values and indexing. f=v^2 will assign
the value v^2 to the function f[z] for z=1, indexing f[]=v^2 mean that the first component
of the vector f has the value v^2. How ever here is a working example

(*
PARAMETER IS: f[]
*)
Clear[ f,calc ];
f={0.};
calc[ v_Real ] := ( f[] = v^2; 0 )
NDSolve[ {dummy'[t] ==calc[p[t]], dummy==0,
p'[t] == -p[t] + f[], p==0 },
{dummy,p}, {t,0,1},Compiled->False ]

{{dummy -> InterpolatingFunction[{0., 1.}, <>],

p -> InterpolatingFunction[{0., 1.}, <>]}}

Hope that helps
Jens

==== [MESSAGE SEPARATOR] ====

```

• Prev by Date: Re: Re: Student v. Full version of Mathematica
• Next by Date: Re: More Anomalous Behaviour with Indexed Variables
• Previous by thread: Re:More Anomalous Behaviour with Indexed Variables
• Next by thread: Re: More Anomalous Behaviour with Indexed Variables