# Dynamic Optimization Using Local Collocation Methods and Improved Multiresolution Technique
## 4 Numerical Examples
### Drug Displacement Problem  
In this example, we consider a time-optimal drug displacement problem [40], where it is shown that the proposed method is also applicable for the optimizing continuous chemical process. The problem simulates the drug interaction of the two drugs warfarin and phenylbutazone in a patient's bloodstream. The problem is to control the rate of infusion of the pain-killing drug phenylbutazone so that the desired level of two drugs can be reached in the minimum time and the concentration of warfarin does not rise above a toxic level during the dynamic process. This problem is expressed as: minimize the final time  
\[J\ =\ t_{f}, \tag{20}\]  
subject to the state dynamics  
\[ \begin{array}{l}\frac{\mathrm{d}x_{1}}{\mathrm{d}t}=\frac{\mathrm{C}_{1}{}^ {2}[\mathrm{C}_{3}(0.02-x_{1})+46.4x_{1}(u-2x_{2})]}{\mathrm{C}_{4}},\\ \frac{\mathrm{d}x_{2}}{\mathrm{d}t}=\frac{\mathrm{C}_{1}{}^{2}[\mathrm{C}_{2} (u-2x_{2})+46.4x_{2}(0.02-x_{1})]}{\mathrm{C}_{4}},\end{array}  \tag{21}\]  
where the state variables \(x_{1}\) and \(x_{2}\) are the concentrations of warfarin and phenylbutazone respectively, \(u\) is the control variable, and \(C_{1}\), \(C_{2}\), \(C_{3}\), and \(C_{4}\) are defined as follows:  
\[ \begin{array}{l}C_{1}=1+0.2x_{1}+0.2x_{2},\\ C_{2}=\mathrm{C}_{1}{}^{2}+232+46.4x_{2},\\ C_{3}=\mathrm{C}_{1}{}^{2}+232+46.4x_{1},\\ C_{4}=C_{2}C_{3}-(46.4){}^{2}x_{1}x_{2}.\end{array} \]  
Figure 4: Mesh refinement history of the control solution for a simple chemical reaction problem: (**a**) Iteration 1; (**b**) iteration 2; (**c**) iteration 6; (**d**) iteration 7. The initial and the terminal conditions are  
\[x_{1}(0)=0.02,x_{1}(t_{f})=0.02,x_{2}(0)=0,x_{2}(t_{f})=2. \tag{22}\]  
The control bounds are  
\[0\leq u(t)\leq 8. \tag{23}\]  
The path constraint on the concentration of warfarin is  
\[x_{1}(t)\leq\alpha, \tag{24}\]  
where \(\alpha\) is the allowable upper limit for the concentrations of warfarin, and \(\alpha=0.026\). We solved this problem using the proposed method with \(N=10,J_{\max}=6\) and \(\varepsilon=0.05\). Note that the parameter \(N\) was specially chosen to not equal \(2^{j}\) (\(j\) is an integer). We first solved the problem without considering the path constraint of Equation (24). The method stopped after seven iterations. Figure 5 shows the control solution and the mesh refinement history. It is seen in Figure 5a that the control solution was a bang-bang solution and the switching point in the control profile was captured accurately, as shown in the two insets in Figure 5a. The mesh point history in Figure 5b shows that the mesh size did not grow much as the mesh refinement proceeded, because most of the unnecessary points were removed. As a result, the method used only 20 points of the maximum of 641 points at the finest resolution mesh \(V_{6,\,N}\). The objective function value was \(J^{*}=221.2748\) s, which is slightly smaller than the value of 221.4661 s obtained in [40] using the indirect multiple shooting algorithm. The CPU time required to solve this problem was 0.98 s.  
The time histories of the two states are shown in Figure 6. The circle markers denote the discrete solutions, and the solid lines are the results obtained by integrating of the state dynamics along the optimal control solution using the classical fourth-order RK method. It is seen in Figure 6 that the two results are in excellent agreement, and both the two states achieved the required values at the terminal time. It should be noted that the maximum concentration of warfarin exceeded the allowable upper limit, because the path constraint of Equation (24) was not considered. Figure 5: Control solution and mesh history for a drug displacement problem (without path constraint): (**a**) \(u(t)\); (**b**) mesh refinement history. We then solved this problem again with the path constraint of Equation (24) considered. The method stopped after seven iterations and selected 45 mesh points from \(V_{6,\,N}\).