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

Next Comment >Help | Reply To Topic
Author Comment/Response
Stan
06/27/12 10:31am

What I want to do is to solve a diff equation in time that has some parameter in it, then define a new function of the solution and then find which value of the parameter maximizes the function at a particular instant.

So for example I could try something like this:

l[(k_)?NumericQ] := NDSolve[{y''[x] + (k + Sin[x]^2) y[x] == 0, y'[0] == 0, y[0] == 0.5}, y, {x, 0, 120}]

L[k_, t_] := (y[t] /. l[k]) ^2

Now I have a function L[k,t] which is the square of the solution of the diff equation. I can plot it as a function of k for, say, t=30 and see that it has a global maximum at about k=0.4. However, when I try to find the maximum using

Maximize[{L[k, 30], 0 < k < 2}, k]

I get an error:

"ReplaceAll::reps: {l[k]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing."

What am I doing wrong? Or is there perhaps a better way of doing this altogether?

I could of course find the maxima by looking at the plot but I would need to do that a lot so I would prefer it if it could be automated.

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
Next Comment >Help | Reply To Topic