Re: NDSolve problem

• To: mathgroup at smc.vnet.net
• Subject: [mg6528] Re: [mg6511] NDSolve problem
• From: Allan Hayes <hay at haystack.demon.co.uk>
• Date: Sun, 30 Mar 1997 22:24:07 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Zahir Bishnani <z.bishnani at damtp.cam.ac.uk>
[mg6511] NDSolve problem

>>>>>>>>>>>
I am trying to solve a scalar ODE numerically but since evaluating
the derivative involves a FindRoot operation, I get error messages.

Example:

If the function that gives the derivative is

FFunc1[y_]:= theta /. FindRoot[Cos[y*theta]==0.0, {theta,2,5}];

Trying NDSolve as follows just spouts out errors

NDSolve[{y'[x]==FFunc1[y[x]], y[0]==1.}, {y}, {x,0,1}]

<<<<<<<<<<<<

Zahir
The problem arises from the way that you are using FindRoot.
Trace the evaluation of FFunc1 by using a variant that prints out
the values of theta as it is evaluated.

FFunc1P[y_]:=
theta /. FindRoot[Print[theta];Cos[y*theta]==0.0, {theta,2,5}];

For example (leaving out the message)

FFunc1P[0.005]
2.
5.
2.
5.
60.6231
631.9
339.622
306.864
314.173
314.159
314.159

Try some more values for y.
The roots that you find are all over!

The graph

Plot[Cos[3 x], {x,-1,6}]

explains this.

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk

```

• Prev by Date: non-negative least squares
• Next by Date: Re: Symbols, names, objects
• Previous by thread: Re: NDSolve problem
• Next by thread: Re: Bug: V.3 for PowerMac