       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:=
Clear[f];
f[x0_?NumericQ, y0_?NumericQ] :=
Module[{sol, x, y},
(sol = NDSolve[{x'[t] == x[t], y'[t] == y[t], x == x0,
y == y0}, {x, y}, {t, 0, 1}];
{x, y} /. sol[])]

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

Out= {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 == x0,
>      y == y0}, {x, y}, {t, 0, 1}];
>   {x, y} /. sol[]
>   )
>
> (*f[x0_, y0_]:={x0 Exp, y0 Exp}; (* Works for this f *) *)
> FindRoot[f[x0, y0] == {2.7, 5.4}, {{x0, 1}, {y0, 2}}]
>
> working?
>