MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: solving simple ODE using NDSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6546] Re: [mg6498] solving simple ODE using NDSolve
  • From: David Withoff <withoff>
  • Date: Mon, 31 Mar 1997 23:01:44 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

> I am trying to solve a scalar ODE numerically but since evaluating the
> derivative involves a FindRoot operation, I get error messages.
>
> Example:
>
> Given the derivative function
>
> FFunc1[y_]:= theta /. FindRoot[Cos[y*theta]==0.0, {theta,2,5}];
>
> which is pretty much equivalent to
>
> FFunc2[y_]:= N[ArcCos[0]/y];
>
> Trying NDSolve as follows just spouts out errors
>
> NDSolve[{y'[x]==FFunc1[y[x]], y[0]==1.}, {y}, {x,0,1}]
>
> FindRoot::precw: Warning: The precision of the argument function
>         (Cos[y[x] theta] - 0.) is less than WorkingPrecision (16).
> FindRoot::frnum: Function {Cos[2. y[x]]} is not a length 1 list
>         of numbers at theta = 2..
> ReplaceAll::reps: {FindRoot[Cos[y[x] theta] == 0., {theta, 2, 5}]}
>         is neither a list of replacement rules nor a valid dispatch
>         table, and so cannot be used for replacing.
>
> Does anyone know how I could get around this problem?
>
> Cheers,
>
> Zahir

You can either ignore the FindRoot::precw warning, or better yet, you
can get rid of it by using an exact zero in place of 0.0 in the
input to FindRoot.  The message in

In[1]:= FindRoot[Cos[x] == 0.0, {x, 1, 2}]

FindRoot::precw:
   The precision of the argument function (Cos[x] - 0.
    ) is less than WorkingPrecision (16).

Out[1]= {x -> 1.5708}

is generated because the precision (the number of non-zero significant
digits) of 0.0 is zero, which is less than the default working precision
of FindRoot.  I recommend using an exact zero.

You can get rid of the other messages by using

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

so that the rule for FFunc1 doesn't get used until numerical values
are assigned to the argument.  This rule doesn't make sense unless y
has a numerical value.

Even with these two changes, you may still have problems, but they
appear to be mathematical problems rather than Mathematica problems.
Part of the problem is that, for some values of y, there are
at least two roots of Cos[y*theta]==0 for 2 < y < 5, and FindRoot
will not necessarily converge to the one that you want.  My guess
is that you will need to be more careful about choosing starting
values for FindRoot, rather than using 2 and 5 throughout the calculation.

Dave Withoff
Wolfram Research


  • Prev by Date: Re: Fourier Transforms and Integers
  • Next by Date: Re: Symbols, names, objects: kludge
  • Previous by thread: Re: Fourier Transforms and Integers
  • Next by thread: thanks