# Interactive Airfoil Optimization Using Parsec Parametrization and Adjoint Method
## 4 Airfoil Optimization: Governing Equations and Implementation
### Adjoint-Based Optimization with Panel Method and Parsec Parametrization  
To obtain the equations for the adjoint optimization, it is necessary to start with Equations (9) and (23). Matrix \(\mathbf{A}\) and vector \(\mathbf{b}\) are known from [20]. The only part that must be specified in Equation (9) is its right-hand side, which contains, in this context, the gradient of \(I\) with respect to \(\hat{\mathbf{w}}\). \[\bigg{(}\frac{\partial I}{\partial\hat{\mathbf{w}}}\bigg{)}=2(\mathbf{\Delta x}\hat{ \mathbf{c}}_{t})^{T}\mathbf{C},\hskip 14.226378 pt(\mathbf{\Delta x}\hat{\mathbf{c}}_{t})= \begin{bmatrix}\Delta x_{1}\hat{c}_{t1}\\ \vdots\\ \Delta x_{N}\hat{c}_{tN}\end{bmatrix}  \tag{25}\]  
In (25), \(\mathbf{C}\) is defined as follows:  
\[C_{ik}=\frac{\partial\hat{c}_{ti}}{\partial\hat{w}_{k}}=\frac{1}{2\pi}\bigg{(} \sin(\theta_{i}-\theta_{k})\beta_{ik}-\cos(\theta_{i}-\theta_{k})\ln\frac{ \tau_{ik+1}}{\tau_{ik}}\bigg{)}\hskip 14.226378 ptfor\hskip 2.845276 ptk=1 \div N \tag{26}\]  
\[C_{iN+1}=\frac{\partial\hat{c}_{ti}}{\partial\hat{w}_{N+1}}=\frac{1}{2\pi} \sum\limits_{j=1}^{N}\left(\sin(\theta_{i}-\theta_{j})\ln\frac{\tau_{ij+1}}{ \tau_{ij}}+\cos(\theta_{i}-\theta_{j})\beta_{ij}\right) \tag{27}\]  
Figure 4: Node and panel numbering in the panel method. The definition of the gradient comes directly from (10), and its constituent derivatives are specified in (28) and (29). \[\frac{\partial I}{\partial F_{k}}=2{\sum\limits_{i=1}^{N}}\Delta x_{i}\hat{c}_{ ti}\frac{\partial\hat{c}_{ti}}{\partial F_{k}} \tag{28}\]  
\[\frac{\partial R_{l}}{\partial F_{k}}=\frac{\partial}{\partial F_{k}}\Big{(}A_ {lm}\hat{w}_{m}-\hat{b}_{l}\Big{)}=\frac{\partial A_{lm}}{\partial F_{k}}\hat{ w}_{m}-\frac{\partial\hat{b}_{l}}{\partial F_{k}} \tag{29}\]  
Now, it is possible to continue processing the individual terms in Equations (28) and (29). The derivatives of the vectors \(\hat{c}_{t}\) and \(\hat{b}\), and matrix \(A\) can be obtained semi-analytically, greatly reducing the number of numerical derivatives computed, which saves a lot of computational costs. It can be shown that only the following derivatives must be computed numerically:  
\[\frac{\partial\theta_{i}}{\partial F_{k}},\hskip 14.226378 pt\frac{\partial \theta_{ij}}{\partial F_{k}},\hskip 14.226378 pt\frac{\partial r_{ij}}{ \partial F_{k}} \tag{30}\]  
To evaluate these derivatives, the first forward difference is used. This approximation is first-order accurate but computationally very cheap. Because the code runs in MATLAB R2023b, which uses double precision as standard, a rather small step when evaluating the finite difference can be used without losing precision to rounding errors. It has been found that the value \(\delta=10^{-8}\) gives accurate results and a stable optimization algorithm. The value \(\delta=10^{-9}\) has been tried out without any noticeable improvement in precision or stability. All the numerical derivatives are computed as presented in (31). \[\frac{\partial r_{ij}}{\partial\bar{F}_{k}}\cong\frac{r_{ij}(F_{1},\ldots,F_{ k-1},F_{k}+\delta,F_{k+1},\ldots,F_{m})-r_{ij}(F_{1},\ldots,F_{m})}{\delta} \tag{31}\]  
Now, it is possible to define the following auxiliary variables. These variables arise when obtaining the analytical derivatives of individual terms in (28) and (29). They are not essential for the math, but they make programming implementation easier and far cleaner.