Re: RE: The equivalent of FindRoot for an interpolating function
- To: mathgroup at smc.vnet.net
- Subject: [mg37516] Re: [mg37501] RE: [mg37470] The equivalent of FindRoot for an interpolating function
- From: "Philip M. Howe" <pmhowe at lanl.gov>
- Date: Sat, 2 Nov 2002 03:31:14 -0500 (EST)
- References: <200211010644.BAA11384@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
>Hi All,
Many thanks to all who replied to my query. As usual, I learned a
lot from this group.
My reason for asking for a solution was that I had originally tried
using FindRoot, and became uncomfortable with it. Findroot seems to
work well, as long as one is careful in one's choice of initial
guesses.
I have a large number of calculations to do, with a wide range in the
solution choices. Hence, I chose my guess for the solution rather
cavalierly as a fraction of the max time I was interested in. This
led to some bad answers. At first I thought the problem was my
choice of .99 or .999 , where my interest lies. However, the problem
exists elsewhere (the example I have chosen here was chosen because
it also has an exact solution; the system I am interested in must be
solved numerically).
With an appropriate initial guess, FindRoot gives good answers (for
this problem) over a wide range of max times and a wide range of
intersection points. Even so, there are some traps (see the table
below). I was surprised to see the bad behavior for w=0.3 and an
initial guess of 1.1. This behavior shows up at other places, for
larger values of tmax.
Clear[y, t, tmax];
tmax = 10;
sol = NDSolve[{y'[t] == 1 - y[t], y[0] == 0}, y, {t, 0., tmax}];
fy = y /. sol[[1]];
Plot[fy[t], {t, 0, tmax}, PlotRange -> All];
Clear[g, xx, y, t, tmax, w];
g[tmax_, w_] :=
Module[{y, sol, t, fy},
sol = NDSolve[{y'[t] == 1 - y[t], y[0] == 0}, y, {t, 0., tmax}];
fy = y /. sol[[1]];
FindRoot[fy[t] == w, {t, .1tmax}][[1, 2]]];
Table[Table[g[n, w], {n, 7, 40}], {w, .1, .9, .1}] // MatrixForm
I was unable to get Bobby's inverse method to work. It looks very
interesting, and I will play with it some more.
After reading Sergio Milo's suggestion, the approach of forming a
table of y[t] and t and using Interpolation to form the inverse
interpolating function occurred to me. This seems quite robust - at
least, I haven't been able to get it to fail yet. Here is one
example:
tmax = 10;
sol = NDSolve[{y'[t] == 1 - y[t], y[0] == 0}, y, {t, 0., tmax}];
fy = y /. sol[[1]];
Plot[fy[t], {t, 0, tmax}, PlotRange -> All];
z = Interpolation[Table[{fy[t], t}, {t, 0, tmax, .1}]];
Plot[z[y], {y, 0, 1}, PlotRange -> All];
z[.3]
I look forward to trying Ted Ersek's package, as suggested by David Park.
Regards,
Phil
>Use the inverse function computed as follows:
>
>sol = NDSolve[{y'[t] == 1 - y[t], y[0] == 0}, y, {t, 0, 20}]
>fy = y /. sol[[1]]
>Dimensions /@ (List @@ fy)
>data = Reverse /@ First@
> Cases[Plot[fy[x], {x, 0, 20}, PlotRange -> All], Line[a_] -> a, 3];
>inverse = Interpolation[data]
>Plot[inverse[x], {x, 0, 1}, PlotRange -> All]
>
>DrBob
>
>-----Original Message-----
>From: Philip M. Howe [mailto:pmhowe at lanl.gov]
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg37516] [mg37501] [mg37470] The equivalent of FindRoot for an interpolating
>function
>
>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
--
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
- References:
- RE: The equivalent of FindRoot for an interpolating function
- From: "DrBob" <drbob@bigfoot.com>
- RE: The equivalent of FindRoot for an interpolating function