I've solved a system of two ODEs using NDSolve which look like this
$\qquad y''-ky'=c, \quad y(t=0)=y_0, \quad y'(t=0)=\sin(a)$ $\qquad x''-kx'=0, \quad x(t=0)=x_0, \quad x'(t=0)=\cos(a)$
Where $c,q,k,a,y_0,x_0$ are constants.
I used NDSolve
and obtained the y-x plot via ParametricPlot
and added a Manipulate command to change parameters $k, a$ as the following:
k = 0.2;
x0 = 0;
y0 = 0;
c = 2;
T = 2;
Manipulate[
ParametricPlot[
Evaluate[
{x[t], y[t]} /.
(NDSolve[
{y''[t] - c - k*y'[t] == 0, y[0] == y0, y'[0] == Sin[a],
x''[t] - k*x'[t] == 0, x[0] == x0, x'[0] == Cos[a]},
{x, y}, {t, 0, T}])],
{t, 0, T},
PlotRange -> All],
{k, 0, 0.5},
{a, 0, Pi/2}]
Now I want to find the optimum value for $a$ so that $x(t(y=b))$ for any given $k$ is maximum.
To find $t(y=b)$, I tried using NSolve
as in the following, but somehow it's giving weird answers:
Manipulate[
NSolve[
Evaluate[
{x[t], y[t]} /.
(NDSolve[
{y''[t] + g - k*y'[t] == 0, y[0] == y0, y'[0] == v0*Sin[theta]},
{y}, {t, 0, T}])] == b, t],
{k, 0, 0.5},
{a, 0, Pi/2}]
What am I doing wrong? How does optimization works in Mathematica?
ParametricNDSolve[]
. $\endgroup$ – J. M.'s ennui♦ Mar 19 '18 at 22:55a
specified, find the value ofa
that maximizesx[t]
subject to the constrain thaty[t] == b
. Is that correct? If so, try,NMaximize
. $\endgroup$ – bbgodfrey Mar 21 '18 at 4:28b
? $\endgroup$ – bbgodfrey Mar 21 '18 at 4:33