
\subsection{Continuous-Time Uncertain Examples}

Code is available at \url{github.com/jarmill/peak}, and is written in Matlab R2020a using
Gloptipoly3 \cite{henrion2003gloptipoly}, 
YALMIP \cite{Lofberg2004}, 
and Mosek 9.2 \cite{mosek92} 
to formulate and solve LMIs.
Demonstrations are available in the folder \texttt{peak/experiments\_uncertain} and are run here on an Intel i9 CPU at 2.30 GHz with 64.0 GB of RAM. 

Dynamics based on Example 1 of \cite{xue2019inner} (adding $w$) are,
\begin{equation}
\label{eq:ex_inner}
    \dot{x}(t) = \begin{bmatrix}-0.5x_1 - (0.5 + w(t)) x_2 + 0.5 \\ -0.5 x_2 + 1 + \theta. \end{bmatrix}
\end{equation}

Figure \ref{fig:inner} illustrates maximization of $p(x) = x_1$ starting in $X_0 = \{x \mid (x_1 + 1)^2 + (x_2 + 1)^2 \leq 0.25\}$ for time $t \in [0, 10]$. The admissible disturbances $w(t)$ are in $w = [-0.2, 0.2]$. Fig. \ref{fig:inner_d} has $\Theta = 0$ while Fig. \ref{fig:inner_d_w} has $\Theta = [-0.5, 0.5]$ for the time-independent uncertainty $\theta \in \Theta$. In each figure, the black circles are initial conditions from the boundary of $X_0$, the blue curves are sampled trajectories, and the red plane are level sets for upper bounds of $x_1$ along trajectories. At the order $r=4$ LMI relaxation, Fig. \ref{fig:inner_d} yields a bound of $P^* \leq 0.4925 $ while Fig. \ref{fig:inner_d_w} with $\theta$ results in $P^* \leq 0.7680$. The black surface containing all trajectories in Fig. \ref{fig:inner_d} is the level set $\{(t,x) \mid v(t, x) = 0.4925\}$. 
% \urg{An auxiliary function $v(t, x, w)$ exists for \ref{fig:inner_d_w}, but this $v$ would require projections and be less clear to  visualize.}




\begin{figure}[ht]
     \centering
     \begin{subfigure}[b]{0.48\linewidth}
         \centering
         \includegraphics[width=\linewidth]{inner_d_ax_compressed.pdf}
         \caption{$\theta = 0$}
         \label{fig:inner_d}
     \end{subfigure}
     \;
     \begin{subfigure}[b]{0.48\linewidth}
         \centering
         \includegraphics[width=\linewidth]{inner_d_w_ax_compressed.pdf}
         \caption{$\theta \in [-0.5, 0.5]$}
         \label{fig:inner_d_w}
     \end{subfigure}
      \caption{\label{fig:inner} Maximize $x_1$ at order 4 with $w(t) \in w$}
\end{figure}


% \urg{replace this with an example with $b$}
% Section 4.1 of \cite{henrion2012measures} introduces a 1DOF attitude controller with linearized dynamics corresponding to a double-integrator $I \ddot{\theta} = u$ and states $x = [\theta, \dot{\theta}]$. The input $u = \textrm{sat}_L(Kx)$ is a state feedback controller $Kx = 1000(2.475 \theta + 19.8 \dot{\theta})$ that saturates at levels $\pm L= \pm 380$. The subsystems are  linear operation $\abs{Kx} \leq L$, positive saturation $Kx \geq L$, and negative saturation $Kx \leq -L$ (deterministic switching).
% These valid regions $X^k$ are separated in Fig. \ref{fig:space_all} by thin dotted diagonal lines. Maximizing $p(x) = \abs{\theta}$ (implemented as $\theta^2$) is shown in Fig. \ref{fig:space}. With $\abs{\theta_0} \leq 15^\circ$ and $\abs{\dot{\theta}_0} \leq 3^\circ/\textrm{sec}$, a degree-5 approximation finds a time-independent upper bound of $\abs{\theta_*} = 20.69^\circ$. The blue curve is the near-optimal trajectory, starting at the blue circle and extremizing $p(x)$ at the blue star.
% The nominal moment of inertia in Fig. \ref{fig:space} is $I = 27,500 \ kg \;m^2$. Time-independent relative uncertainty $I$ may be introduced by replacing $I$ with $I/(1+w)$, where $w \in [-0.5, 0.5]$. The peak angle is raised to $\abs{\theta_*} = 51.86^\circ$ at $d=5$ at $I' = 2 I$ with this new uncertainty in Fig. \ref{fig:space_w}.


% \begin{figure}[ht]
%      \centering
%      \begin{subfigure}[b]{0.48\linewidth}
%          \centering
%          \includegraphics[width=\linewidth]{space_const_sat.pdf}
%          \caption{Certainty in $I$}
%          \label{fig:space}
%      \end{subfigure}
%      \;
%      \begin{subfigure}[b]{0.48\linewidth}
%          \centering
%          \includegraphics[width=\linewidth]{space_w_sat.pdf}
%          \caption{50\% uncertainty in $I$}
%          \label{fig:space_w}
%      \end{subfigure}
%       \caption{\label{fig:space_all} Maximum angle for 1DOF attitude controller \\
%       \urg{get rid of legends}}
% \end{figure}

The reduced three-wave model is a nonlinear model for the interaction of three quasisynchronous waves in a plasma \cite{goriely2001integrability}. These dynamics with parameters $(A, B, G)$ are,
\begin{align}
    \dot{x_1} &=  A x_1 + B x_2 + x_3 -2 x_2^2 \nonumber \\
    \dot{x_2} &= -B x_1 + A x_2 + 2 x_1 x_2 \label{eq:three_wave}\\
    \dot{x_3} &= -G x_3 - 2 x_1 x_2. \nonumber
\end{align}
This example aims to maximize $x_2$ on the three-wave system starting in $X_0 = \{x \mid (x_1+1)^2 + (x_2+1)^2 + (x_3+1)^2 \leq 0.16\}$. Order 3 LMI relaxations are used to upper bound $x_2$ over the region of interest $X = [-4, 3] \times [0.5, 3.6] \times [0, 4]$  and times $t \in [0, 5]$. The bound $P^* \leq 2.6108$ is produced with parameter values $A = 1, \; B = 0.5, \; G = 2$ (no uncertainty), as illustrated in Fig. \ref{fig:three_wave_std}. 
% This upper bound is nearly tight (as verified by Algorithm 1 from \cite{miller2020recovery}), and the recovered optimal trajectory is shown in blue starting from $[1.392, 0.962, 1.056]$ (circle) and maximizing $x_2$ at $[-0.553, 2.611, 0.223]$ (star). 
Fig. \ref{fig:three_wave_unc} adds uncertainty by letting $A \in [-0.5, 1.5]$ and $B \in [0.25, 0.75]$ vary arbitrarily with time, and $G$ now possesses parametric uncertainty in $[1.9, 2.1]$ . Uncertainty in $A, B$ are realized by switching between 4 subsystems of \eqref{eq:three_wave} with  $(A, B) \in \{0.5,1.5\} \times \{0.25, 0.75\}$
Uncertainty in $G$ is implemented as $G = 2 + \theta$ where $\theta \in [-0.1, 0.1]$. 
The order-3 bound under uncertainty in Fig. \ref{fig:three_wave_unc} is $P^* \leq 3.296$. 
% Mosek took 0.59 seconds to solve the $d = 0$ LMI and 81.2 seconds to solve the $(A, B)$ varying $b$-formulated LMI.
% Without using box structure $(d \in [0, 1]^2)$, the computed order-4 bound is $P^* \leq 3.121$ requiring 47.0 min to solve the LMI.

% \urg{TODO: Use switching on the three-wave system, replace box uncertainty}


% The three-wave system is studied over the region $X = [] \times [] \times []$ for $t \in [0, 5]$. In this example, the parameters


\begin{figure}[ht]
     \centering
     \begin{subfigure}[b]{0.48\linewidth}
         \centering
         \includegraphics[width=\linewidth]{three_wave_3.png}
         \caption{no uncertainty}
         \label{fig:three_wave_std}
     \end{subfigure}
     \;
     \begin{subfigure}[b]{0.48\linewidth}
         \centering
         \includegraphics[width=\linewidth]{three_wave_3_w_switch.png}
         \caption{with uncertainty}
         \label{fig:three_wave_unc}
     \end{subfigure}
      \caption{\label{fig:three_wave} Maximize $x_2$ on three-wave system \eqref{eq:three_wave}
      }
\end{figure}

% \urg{content goes here}

% \urg{Talk about complexity? Sizes and quantities of the moment matrices. Why the switching and box formulations are so important.}
% The time complexity of LMI relaxations to measure programs scale combinatorially with the the number of variables in a measure, 

% Finite-degree LMI relaxations 

% The moment matrix 

  