MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111362] Re: FindRoot with NDSolve inside of it doesn't work
  • From: Sam Takoy <sam.takoy at yahoo.com>
  • Date: Thu, 29 Jul 2010 06:42:03 -0400 (EDT)

Hi,

Thanks for the response.

I have determined that  introducing ?NumericQ alone works and I am wondering 
why?

How is the "f" that involves NDSolve fundamentally different from 

f[x0_,y0_]:={x0 Exp[1],y0 Exp[1]}

?

Thanks again,

Sam



________________________________
From: Leonid Shifrin <lshifr at gmail.com>
To: Sam Takoy <sam.takoy at yahoo.com>; mathgroup at smc.vnet.net
Sent: Wed, July 28, 2010 6:03:47 AM
Subject: [mg111362] Re: [mg111343] FindRoot with NDSolve inside of it doesn't work


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}}]
>
>Can someone please help me fix this and explain why it's not currently
>working?
>
>Many thanks in advance!
>
>Sam
>
>


  • Prev by Date: Re: Writing to same file from several kernels?
  • Next by Date: Re: NDSolve - how to bypass safety chceck?
  • Previous by thread: Re: FindRoot with NDSolve inside of it doesn't work
  • Next by thread: Re: FindRoot with NDSolve inside of it doesn't work