       More Anomalous Behaviour with Indexed Variables

• Subject: [mg3256] More Anomalous Behaviour with Indexed Variables
• From: mrj at cs.usyd.edu.au (Mark James)
• Date: 21 Feb 1996 13:18:00 -0600
• Approved: usenet@wri.com
• Distribution: local
• Newsgroups: wri.mathgroup
• Organization: The University of Sydney
• Sender: daemon at wri.com

```A recent article on this group discussed the frequent failure
of FindRoot when the search variable is indexed (e.g. x).
I have been having similar problems.

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} ]

=====
FURTHER EXPLANATION:

The second differential equation in the first NDSolve call
above depends of a parameter f that is a function of p.

This parameter is calculated as a side effect
of integrating the first differential equation.
(My actual equation set, is 1000 times more complicated than this,
and I really want to use the side effect method to efficiently
calculate a number of parameters each integration step that
would otherwise each be calculated many times per step.)

I have used this method for a year without problems.

But changing the parameter to f does not work.
(I now need to use indexed parameters in my real system.
I have managed to get this real system to work if I substitute
every indexed variable by a non-indexed one: e.g. s -> s1 .)

Am I doing anything wrong, or is it a bug?  If it is a bug:
Is there a workaround?  Will it be fixed in 3.0?
Is this related to similar problems with indexed
variables in FindRoot?