Re: The equivalent of FindRoot for an interpolating function
- To: mathgroup at smc.vnet.net
- Subject: [mg37499] Re: [mg37470] The equivalent of FindRoot for an interpolating function
- From: BobHanlon at aol.com
- Date: Fri, 1 Nov 2002 01:44:15 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 10/31/2002 7:28:19 AM, pmhowe at lanl.gov writes: >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? > The exact solution is y[t] /. DSolve[{y'[t] == 1 - y[t], y[0] == 0}, y[t], t][[1]] // Simplify 1 - E^(-t) sol = y /. NDSolve[{y'[t] == 1 - y[t], y[0] == 0}, y, {t, 0, 20}] [[1]]; f[x_] := t /. FindRoot[sol[t] == x, {t, -Log[1 - x]}]; f /@ {.9, .99, .999, .9999, .99999} {2.302585092994046, 4.605170185988091, 6.907755278982136, 9.210340371976294, 11.51292546497478} Plot[sol[t], {t, 0, 10}]; Plot[f[x], {x, .5, .99999}]; Bob Hanlon