       Re: FindRoot with parameterized interpolated function from NDSolve

• To: mathgroup at smc.vnet.net
• Subject: [mg110759] Re: FindRoot with parameterized interpolated function from NDSolve
• From: Peter Pein <petsie at dordos.net>
• Date: Mon, 5 Jul 2010 06:01:52 -0400 (EDT)
• References: <i0pmlc\$slv\$1@smc.vnet.net>

```Am Sun, 4 Jul 2010 10:09:48 +0000 (UTC)
schrieb Ulvi Yurtsever <a at b.c>:

> I have an interpolated function obtained
> as the solution to a system of ODEs via NDSOlve.
> The system and the solution depend on a number
> of parameters. I then want to plug this function into
> FindRoot to find the numerical solution of a system
> of equations which depend on both the dependent variable
> of the ODEs and the parameters. Mathematica barfs at
> the use of parameters as in the following example:
>
> First, what works as expected:
>
>
> In:= solnn =.
>
> In:=
> solnn[a_] :=
>  NDSolve[{x'[t] == a *y[t], y'[t] == -x[t], x == 1, y == 0}, {x,
>     y}, {t, 0, Pi}]
>
> In:= FindRoot[(x /. solnn[])[t] - (y /. solnn[])[
>     t] == 0, {t, 2}]
>
> Out= {t -> 2.35619}
>
>
> however:
>
>
> FindRoot[{(x /. solnn[a][])[t] - (y /. solnn[a][])[t] == 0,
>   a - 1 == 0}, {{a, 0}, {t, 2}}]
>
>
> produces, instead of the expected
>
> {a->1., t->2.355619},
>
> lots of error messages to the effect that NDSolve has encountered non-
> numerical initial values etc
>
> Is there any  other way to use FindRoot for the purpose I am trying
> to use it?
>

Define an auxilliary function which evaluates iff a _and_ t have got
numeric values (I changed solnn a bit for better handling):

In:= Clear[solnn,x,y];
solnn[a_?NumericQ] :=
Block[{t},
First[
NDSolve[{x'[t] == a*y[t], y'[t] == -x[t], x==1, y == 0},
{x, y}, {t, 0, Pi}]
]]

In:= FindRoot[x[t] - y[t] == 0 /. solnn, {t ,2}]
Out= {t->2.35619}

In:= target[a_?NumericQ, t_?NumericQ] := x[t] - y[t] /. solnn[a]
In:= FindRoot[{target[a, t] == 0, a - t/3 == 0},
{{a, 0}, {t, 2, 0, Pi}}]
Out= {a->0.860285,t->2.58085}

Peter

```

• Prev by Date: Re: FindRoot with parameterized interpolated function from NDSolve
• Next by Date: Re: Is it possible to query current plot range values (or have
• Previous by thread: Re: FindRoot with parameterized interpolated function from NDSolve
• Next by thread: Re: FindRoot with parameterized interpolated function from NDSolve