Re: FindRoot with NDSolve inside of it doesn't work

• To: mathgroup at smc.vnet.net
• Subject: [mg111356] Re: FindRoot with NDSolve inside of it doesn't work
• From: Leonid Shifrin <lshifr at gmail.com>
• Date: Wed, 28 Jul 2010 07:26:10 -0400 (EDT)

```Sam,

This modification will work:

In[31]:=
Clear[f];
f[x0_?NumericQ, y0_?NumericQ] :=
Module[{sol, x, y},
(sol = NDSolve[{x'[t] == x[t], y'[t] == y[t], x[0] == x0,
y[0] == y0}, {x, y}, {t, 0, 1}];
{x[1], y[1]} /. sol[[1]])]

In[33]:=
(*f[x0_,y0_]:={x0 Exp[1],y0 Exp[1]};(*Works for this f*)*)
FindRoot[f[x0, y0] == {2.7, 5.4}, {{x0, 1}, {y0, 2}}]

Out[33]= {x0 -> 0.993274, y0 -> 1.98655}

Apart from localizing your variables, the main thing here was to restrict x0
and y0
as input parameters to <f>, to only numeric values, by  appropriate
patterns.

Regards,
Leonid

On Wed, Jul 28, 2010 at 10:54 AM, Sam Takoy <sam.takoy at yahoo.com> wrote:

> Hi,
>
> I think it's completely self-explanatory what I'm trying to do in this
> model example:
>
> f[x0_, y0_] := (
>   sol = NDSolve[{x'[t] == x[t], y'[t] == y[t], x[0] == x0,
>      y[0] == y0}, {x, y}, {t, 0, 1}];
>   {x[1], y[1]} /. sol[[1]]
>   )
>
> (*f[x0_, y0_]:={x0 Exp[1], y0 Exp[1]}; (* Works for this f *) *)
> FindRoot[f[x0, y0] == {2.7, 5.4}, {{x0, 1}, {y0, 2}}]
>
> working?
>