Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Maximizing solutions of NDSolve' topicStudent Support Forum > General > Archives > "Maximizing solutions of NDSolve"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Stan
06/29/12 08:05am

I've come up with a possible workaround but for some reason it gives results that are clearly wrong.

What I did is calculate points for the fuction L and fitted an interpolation function to those points and then maximized the interpolation function. This doesn't produce an error but gives clearly wrong results. With the example in the post above:

l[(k_)?NumericQ] := NDSolve[{y''[x] + (k + Sin[x]^2) y[x] == 0, y'[0] == 0, y[0] == 0.5}, y, {x, 0, 30}]
L[k_, t_] := (y[t] /. l[k])^2
data = Table[{k, First[L[k, 30]]}, {k, 0, 10, 0.001}];
f = Interpolation[data];
Maximize[{f[x], 0 < x < 10}, x]

However this gives

{0.229964, {x -> 6.35663}}

which is obviously wrong. I can see quite clearly by plotting the fuction that the maximum is around x=0.4 and is about 120. In fact if I give this as an argument to the interpolation function it gives

In[06]:=f[0.4]
Out[06]=123.278

which is clearly much larger that what it found to be the maximum. If I give it a range that is around what I know is the maximum it does find it correctly:

In[07]:= Maximize[{f[x], 0 < x < 0.5}, x]
Out[07]= {123.308, {x -> 0.398059}}

Why is it getting the wrong result for a wider range. Or is there a better way of doing this? Any help appreciated.

URL: ,

Subject (listing for 'Maximizing solutions of NDSolve')
Author Date Posted
Maximizing solutions of NDSolve Stan 06/27/12 10:31am
Re: Maximizing solutions of NDSolve Stan 06/29/12 08:05am
Re: Re: Maximizing solutions of NDSolve Michael 06/29/12 12:31pm
Re: Re: Re: Maximizing solutions of NDSolve Stan 06/30/12 12:02pm
Re: Re: Re: Re: Maximizing solutions of NDSolve Michael 07/02/12 01:01am
Re: Maximizing solutions of NDSolve Stan 07/09/12 07:24am
Re: Re: Maximizing solutions of NDSolve Michael 07/10/12 2:30pm
Re: Maximizing solutions of NDSolve Forum Modera... 07/14/12 1:27pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic