| 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: , |
|