MathGroup Archive 2006

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

Search the Archive

Re: FindRoot & NDSolve


Takashi Inoue wrote:

>Hi all,
>
>This is my first post to here.
>I have a problem and want your help.
>
>Mathematica 4 did the following calculation with no pleblem,
>while Mathematica 5(.2)  cannot do it.
>
>FindRoot[
> (f /.NDSolve[ {D[f[x], {x,1}] - 2 x - a == 0, f[0] == 0}, f, {x, -3, 3} 
>][[1]])[2] == 4,
> {a, -10, 10}
>           ]  
>
I think FindRoot requires a initial guess in 5.X and you need some kind 
of looping for your different values of a


Here are two possible alternatives (that I could think of) using DSolve 
and NDSolve

(*Using DSolve (more preferable perhaps because of the closed form nature)*)

TableForm[{#,x/.FindRoot[(f/.DSolve[{D[f[x], {x,1}]== 2 x + #, f[0] == 
0}, f, 
x][[1,1]])[x]==4,{x,1}]//N}&/@Range[-10,10,1],TableHeadings->{Automatic,{"a","Root 
for f[x,a]"}}]

(*Using NDSolve  )

Clear[f,x,a]
Table[Reap[NDSolve[{D[f[x], {x,1}]== 2 x + a, f[0] == 0}, f, {x,-3,3}, 
Method->{EventLocator, 
"Event"->f[x]-4,"EventAction":>Sow[{a,x}]}],{a,-10,10,1}]


Hope this helps

Pratik

>Takashi Inoue,Dept. Phys. Sophia University



  • Prev by Date: Re: FindRoot & NDSolve
  • Next by Date: Re: FindRoot & NDSolve
  • Previous by thread: FindRoot & NDSolve
  • Next by thread: Re: FindRoot & NDSolve