welcome: please sign in
location: Diff for "Computer/Latex/Optimization"
Differences between revisions 2 and 3
Revision 2 as of 2018-07-11 10:16:40
Size: 2671
Editor: leif
Comment:
Revision 3 as of 2018-07-11 10:26:21
Size: 2882
Editor: leif
Comment:
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
This is a simple optimization. Note that the equation number is put at the expression to be minimized, using the command `\tagthis`. For other numbering patterns, see below. This is a simple optimization. Note that the equation number is put at the expression to be minimized, using the command `\tagthis`. For other numbering patterns, see below. Note also that the first column, with 'minimize' and 'subject to', is right aligned, and the second column is left aligned. Other alignments are possible, but this is the simplest and most estetic in my opinion.

Formatting Optimization Problems

Put the following lines in the head of your document, i.e. between \documentclass{xxx} and \begin{document}. The package mathtools is an extension of amsmath, and may be of interest independently of optimization problems.

\usepackage{mathtools}
\newcommand*{\optMinMax}[2]{\underset{\vphantom{A}\displaystyle\mathclap{#1}}%
                           {\text{#2}}\quad}
\newcommand{\optmin}[1]{\optMinMax{#1}{minimize}}
\newcommand{\optmax}[1]{\optMinMax{#1}{maximize}}
\newcommand*{\subject}{\text{subject to}\quad}
\newcommand*{\tagthis}{\stepcounter{equation}\tag{\theequation}}

This is a simple optimization. Note that the equation number is put at the expression to be minimized, using the command \tagthis. For other numbering patterns, see below. Note also that the first column, with 'minimize' and 'subject to', is right aligned, and the second column is left aligned. Other alignments are possible, but this is the simplest and most estetic in my opinion. optim1.png

\begin{align*}\label{eq:QP}
  \optmin{x}  &\dfrac{1}{2}x^THx + f^Tx \tagthis \\
  \subject    & Ax  \leq b \\
              &A_{\text{eq}}x  = b_{\text{eq}}
\end{align*}

optim2.png

\begin{align*}\label{Eq:Ign_Opt}
\optmin{\begin{matrix}\Delta\bm{\theta}_{\mathrm{SOI}},\Delta \theta_{\mathrm{HP}},\\
               \Delta \theta_{\mathrm{LP}},\Delta\theta_{\mathrm{Hot}}\end{matrix}}
         &\sum_{k=1}^{H_p}\biggl(\omega_1||r_{\theta_{50}}(k)-\bm{\theta}_{50}(k)||^2_2 
           + \omega_2 ||r_{\tau}(k)-\bm{\tau}(k)||^2_2  \\[-7mm]
          & \hphantom{\sum} \quad + \omega_3 \theta_{\mathrm{HP}}(k)^2 
            + \omega_4  \theta_{\mathrm{LP}}(k)^2\biggl)  + \cdots \tagthis\\
\subject  & l_b \leq \begin{pmatrix} \bm{\theta}_{\mathrm{SOI}} \\
                \theta_{\mathrm{Hot}} \\ \theta_{\mathrm{HP}} \\ \theta_{\mathrm{LP}} 
                \end{pmatrix} \leq u_b  \\
          & \text{other conditions} 
\end{align*}

optim3.png

\begin{alignat*}{2}\label{Eq:opt1}
  \optmin{\mathbf{u}_1 , \dots , \mathbf{u}_{H_p}} 
           & \sum_{k=1}^{H_p} J_{m_f}(k) + J_{p_{\text{IMEP}}}(k) + J_{\Delta u}(k) \hspace*{-40mm} &&\tagthis\\
  \subject & p_k \leq c_{p_{\text{max} }}              &&\forall\theta,\;k = 1, \ldots, H_p  \\
           & dp/d\theta_k \leq c_{dp_{\text{max}}}    &\quad& \forall\theta,\; k = 1, \ldots, H_p \\
           & \text{NO}_{x}(k) \leq c_{\text{NO}_x}     && k = 1, \ldots, H_p \\
           & T_{\text{ex}}(k) \geq c_{T_{\text{ex} }}  &&k = 1, \ldots, H_p^{T_{\text{ex}}} \\
           & \mathbf{u}(k) \in \mathbb{U}              &&k = 1, \ldots, H_p. 
\end{alignat*}

Computer/Latex/Optimization (last edited 2022-07-21 10:38:26 by leif)