MathGroup Archive 2002

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

Search the Archive

RE: The equivalent of FindRoot for an interpolating function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37480] RE: [mg37470] The equivalent of FindRoot for an interpolating function
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 1 Nov 2002 01:42:55 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Philip,

It is difficult with FindRoot because of the nature of your function and the
inadequacies of FindRoot.

sol = NDSolve[{y'[t] == 1 - y[t], y[0] == 0}, y, {t, 0, 20}]
fy = y /. sol[[1]]
{{y -> InterpolatingFunction[{{0., 20.}}, "<>"]}}
InterpolatingFunction[{{0., 20.}}, "<>"]

Just to see what the function looks like...

Plot[fy[x], {x, 0, 20},
    PlotRange -> {0, 1}];

The InterpolatingFunction is only defined between 0 and 20. That gives
FindRoot lots of problems.

FindRoot[fy[x] == 0.99, {x, 15, 0, 20}]
FindRoot::"regex": "Reached the point \!\({\(-133.32815729997475`\)}\) which
\
is outside the region \!\({\({0.`, 20.`}\)}\)."
{x -> -133.328}

I do not understand why FindRoot doesn't go to a bisection method once it
goes outside the range. I suppose there is a reason.

In any case, Ted Ersek has a much better root finding package called
RootSearch. I believe it is available on MathSource. (My one objection to
the copy of his package that I have is that it is not in a well defined
folder. It was in my ExtraPackages\Enhancements folder, but the name in the
BeginPackage statement did not correspond. So it wouldn't load. I simple
added the Enhancement context to the name and then it loaded. I am not
certain how the MathSource copy works.)

Needs["Enhancements`RootSearch`"]

xsol = RootSearch[fy[x] == 0.99, {x, 0, 20}][[1, 1]]
x -> 4.60521

fy[x] /. xsol
0.99

A very neat package.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/





From: Philip M. Howe [mailto:pmhowe at lanl.gov]
To: mathgroup at smc.vnet.net


Hi Folks,

I wish to find the value of the independent variable in an
interpolating function that makes the dependent variable assume some
value of interest.  For example,

sol = NDSolve[{y'[t] == 1-y[t], y[0]==0}, y, {t, 0, 20}]
fy = y/.sol[[1]]

produces an interpolating function.  I would like to extract the
value of t that yields a value of 0.99 or 0.9999 (say) for y.  Is
there a straightforward way of doing this?

Thanks in advance for the help.

Regards,

Phil
--
Philip M. Howe
Program Manager, Stockpile Surety
Los Alamos National Laboratory

(505) 665-5332
(505) 667-9498
Fax: 505-665-5249
email pmhowe at lanl.gov
Mail Stop P945



  • Prev by Date: Re: OO in Mathematica
  • Next by Date: Re: D&D Dice
  • Previous by thread: Re: RE: The equivalent of FindRoot for an interpolating function
  • Next by thread: Re: The equivalent of FindRoot for an interpolating function