Re: FindRoot & NDSolve

*To*: mathgroup at smc.vnet.net*Subject*: [mg64672] Re: [mg64650] FindRoot & NDSolve*From*: Pratik Desai <pdesai1 at umbc.edu>*Date*: Sun, 26 Feb 2006 05:07:54 -0500 (EST)*References*: <200602250753.CAA13936@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

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

**References**:**FindRoot & NDSolve***From:*Takashi Inoue <takash-i@sophia.ac.jp>