For dynamic system:
$\dot{x}=\frac{df}{dx}+u$
where $f=e^{-x^2}$
It is necessary to develop optimal control, minimizing criterion:
$J= \int_{0}^{t_f} ((\frac{df}{dx})^2+u^2) \,dt $
Algorithm:
We write Hamiltonian: $H=((\frac{df}{dx})^2+u^2)+\lambda (\frac{df}{dx}+u)$
Write costate equation: $\dot{\lambda}=-\frac{dH}{d\lambda}$
Solve equation for control signal $u$: $\frac{dH}{du}=0$
4.Write resulting system of equation:$\begin{cases} \dot{x}=... \\ \dot{\lambda}=... \end{cases}$
- Solve numerically:
I wrote this algorithm to Mathematica. There is my code:
(***)
Clear["Derivative"]
ClearAll["Global`*"]
f = Sech[(x[t] - 2)]
(***-Origin ODE)
eqn = -D[f, x[t]] + u
(***J)
J = Integrate[D[f, x[t]]^2 + u[t]^2, {t, 0, tf}]
(***Hamiltonian)
H = D[f, x[t]]^2 + 2 u^2 + \[Lambda][t] eqn
(***Costate-Equation)
cseqn = Derivative[1][\[Lambda]][t] == -D[H, x[t]]
(***Solution-For-Control-Signal)
Solve[D[H, u] == 0, u]
u = -\[Lambda][t]/4
(***Resulting-system-of-equation)
eqns = {x'[t] == D[f, x[t]] + u, cseqn}
sys = NDSolve[{eqns,
x[0] == 0, \[Lambda][0] == 0}, {x, \[Lambda]}, {t, 0, 150}]
Plot[{Evaluate[x[t] /. sys], 2}, {t, 0, 30}, PlotRange -> Full,
PlotPoints -> 100]
Plot[{Evaluate[D[f, x[t]] /. sys]}, {t, 0, 100}, PlotRange -> Full,
PlotPoints -> 100]
My problems:
- System does not come to a state $\frac{df}{dx}=0$
- I do not know how the minimized / maximized criterion $J$ is formed correctly (at an infinite time interval).
In other words, the system should achieve a state $\frac{df}{dx}=0$ as quickly as possible.
I would be grateful to help in awareness and correcting my mistakes.
J
andH
definition. It should beH = D[f, x[t]]^2 + u^2 + [Lambda][t] eqn
$\endgroup$