Re: FindRoot & NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg64683] Re: [mg64650] FindRoot & NDSolve
- From: Pratik Desai <pdesai1 at umbc.edu>
- Date: Mon, 27 Feb 2006 00:18:32 -0500 (EST)
- References: <200602250753.CAA13936@smc.vnet.net> <44008AE9.6070708@umbc.edu> <44008C23.1030205@umbc.edu>
- Sender: owner-wri-mathgroup at wolfram.com
Pratik Desai wrote:
> Pratik Desai wrote:
>
>> 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}]
>
>
> There is an error in the above code for NDSolve, here is the correct one
> Table[NDSolve[{D[f[x], {x,1}]== 2 x + a, f[0] == 0}, f, {x,-3,3},
> Method->{EventLocator,
> "Event"->f[x]-4,"EventAction":>Print[{a,x}]}],{a,-10,10,1}];
There is an even bigger error (in comprehension) :-[
sorry about that!
Pratik
>
>
>
>>
>>
>> Hope this helps
>>
>> Pratik
>>
>>> Takashi Inoue,Dept. Phys. Sophia University
>>
>>
>>
>>
>>
>
- References:
- FindRoot & NDSolve
- From: Takashi Inoue <takash-i@sophia.ac.jp>
- FindRoot & NDSolve