Main

(:toggle hide gekko button show="Show GEKKO (Python) Code":)

(:div id=gekko:)

(:source lang=python:)

import numpy as np

import matplotlib.pyplot as plt

from gekko import GEKKO

m = GEKKO()

nt = 1001

t = np.linspace(0,np.pi/2,nt)

m.time = t

# Variables

x1 = m.Var(value=0)

x2 = m.Var(value=1)

x3 = m.Var(value=0)

u = m.MV(value=0,ub=1,lb=-1)

u.STATUS = 1

u.DCOST = 0

p = np.zeros(nt)

p[-1] = 1.0

final = m.Param(value=p)

# Equations

m.Equation(x1.dt()==x2)

m.Equation(x2.dt()==u)

m.Equation(2*x3.dt()==x2**2-x1**2)

# Objective Function

m.Obj(x3*final)

m.options.IMODE = 6

m.options.NODES = 4

m.solve()

plt.figure(1)

plt.subplot(2,1,1)

plt.plot(m.time,x1.value,'k:',LineWidth=2,label=r'$x_1$')

plt.plot(m.time,x2.value,'b-',LineWidth=2,label=r'$x_2$')

plt.plot(m.time,x2.value,'k-',LineWidth=2,label=r'$x_3$')

plt.subplot(2,1,2)

plt.plot(m.time,u.value,'r--',LineWidth=2,label=r'$u$')

plt.plot(t,-np.sin(t),'k:',LineWidth=2,label='Exact')

plt.legend(loc='best')

plt.xlabel('Time')

plt.ylabel('Value')

plt.show()

(:sourceend:)

(:divend:)

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

----

!!!! Luus Problem

Attach:download.png [[Attach:dynamic_optimization_luus.zip|Luus Problem in MATLAB and Python]]

See [[https://youtu.be/5qY7WyngRbo|estimation example]] using the same model to explain estimator objectives.
~~<iframe width="560" height="315" src="https://www.youtube.com/embed/jB7WWGHFNIw" frameborder="0" allowfullscreen></iframe>~~

----

!!!! Catalyzed Reaction

Attach:download.png [[Attach:dynamic_optimization_catalyst.zip|Dynamic Optimization Catalyst Solution in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/jB7WWGHFNIw" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

~~!!!! Solution to Aly-Chan Problem~~

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/tY8kyJq4BEY" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

## More Optimal Control Problems

## Main.MoreDynamicOptimizationBenchmarks History

Hide minor edits - Show changes to output

Changed line 99 from:

!!!! [[Main/EconomicDynamicOptimization|~~Commercial~~ Fishery]]

to:

!!!! [[Main/EconomicDynamicOptimization|Maximize Profit (Commercial Fishery)]]

Changed lines 99-105 from:

!!!! Commercial Fishery

Attach:download.png [[Attach:dynamic_optimization_fishery.zip|Economic Optimization of Fishery in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/MA53XPp-a7I" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Attach:download.png [[Attach:dynamic_optimization_fishery.zip|Economic Optimization of Fishery in MATLAB and Python

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/MA53XPp-a7I" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

to:

!!!! [[Main/EconomicDynamicOptimization|Commercial Fishery]]

Changed lines 109-115 from:

!!!! ~~Jennings Problem~~

Attach:download.png [[Attach:dynamic_optimization_jennings.zip|Jennings Problem in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Attach:download.png [[Attach:dynamic_optimization_jennings.zip|Jennings Problem in MATLAB and Python

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

to:

!!!! [[Main/MinimizeFinalTime|Minimize Final Time (Jennings)]]

Added lines 17-69:

(:toggle hide gekko button show="Show GEKKO (Python) Code":)

(:div id=gekko:)

(:source lang=python:)

import numpy as np

import matplotlib.pyplot as plt

from gekko import GEKKO

m = GEKKO()

nt = 1001

t = np.linspace(0,np.pi/2,nt)

m.time = t

# Variables

x1 = m.Var(value=0)

x2 = m.Var(value=1)

x3 = m.Var(value=0)

u = m.MV(value=0,ub=1,lb=-1)

u.STATUS = 1

u.DCOST = 0

p = np.zeros(nt)

p[-1] = 1.0

final = m.Param(value=p)

# Equations

m.Equation(x1.dt()==x2)

m.Equation(x2.dt()==u)

m.Equation(2*x3.dt()==x2**2-x1**2)

# Objective Function

m.Obj(x3*final)

m.options.IMODE = 6

m.options.NODES = 4

m.solve()

plt.figure(1)

plt.subplot(2,1,1)

plt.plot(m.time,x1.value,'k:',LineWidth=2,label=r'$x_1$')

plt.plot(m.time,x2.value,'b-',LineWidth=2,label=r'$x_2$')

plt.plot(m.time,x2.value,'k-',LineWidth=2,label=r'$x_3$')

plt.subplot(2,1,2)

plt.plot(m.time,u.value,'r--',LineWidth=2,label=r'$u$')

plt.plot(t,-np.sin(t),'k:',LineWidth=2,label='Exact')

plt.legend(loc='best')

plt.xlabel('Time')

plt.ylabel('Value')

plt.show()

(:sourceend:)

(:divend:)

Added lines 1-4:

(:title More Optimal Control Problems:)

(:keywords nonlinear control, optimal control, dynamic optimization, engineering optimization, MATLAB, Python, GEKKO, differential, algebraic, modeling language, university course:)

(:description More optimal control problems solved with Dynamic Optimization in MATLAB and Python.:)

(:keywords nonlinear control, optimal control, dynamic optimization, engineering optimization, MATLAB, Python, GEKKO, differential, algebraic, modeling language, university course:)

(:description More optimal control problems solved with Dynamic Optimization in MATLAB and Python.:)

Changed line 3 from:

'''Objective:''' Set up and solve several ~~[[Attach:Dynamic_Optimization_Benchmarks.pdf|dynamic optimization~~ benchmark problems~~]]~~. Create a program'^1^' to optimize and display the results. ''Estimated Time (each): 30 minutes''

to:

'''Objective:''' Set up and solve several optimal control benchmark problems. Create a program'^1^' to optimize and display the results. ''Estimated Time (each): 30 minutes''

Changed lines 62-68 from:

!!!! ~~Luus Problem~~

Attach:download.png [[Attach:dynamic_optimization_luus.zip|Luus~~ Problem in MATLAB and Python~~]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/WIe31dTaW6g" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Attach:download.png [[Attach:dynamic_optimization_luus.zip|

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/WIe31dTaW6g" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

to:

!!!! [[Main/IntegralObjective|Integral Objective (Luus)]]

Changed line 67 from:

<iframe width="560" height="315" src="https://www.youtube.com/embed/~~yuj217itTa8~~" frameborder="0" allowfullscreen></iframe>

to:

<iframe width="560" height="315" src="https://www.youtube.com/embed/WIe31dTaW6g" frameborder="0" allowfullscreen></iframe>

Added lines 55-64:

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

----

!!!! Luus Problem

Attach:download.png [[Attach:dynamic_optimization_luus.zip|Luus Problem in MATLAB and Python]]

Changed line 57 from:

<iframe width="560" height="315" src="https://www.youtube.com/embed/~~MA53XPp-a7I~~" frameborder="0" allowfullscreen></iframe>

to:

<iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe>

Changed lines 34-35 from:

Attach:download.png [[Attach:dynamic_optimization_catalyst.zip|~~Dynamic Optimization Catalyst Solution~~ in MATLAB and Python]]

to:

Attach:download.png [[Attach:dynamic_optimization_catalyst.zip|Catalyzed Reaction Optimized in MATLAB and Python]]

Changed lines 44-45 from:

Attach:download.png [[Attach:dynamic_optimization_fishery.zip|~~Dynamic~~ Optimization Fishery ~~Solution ~~in MATLAB and Python]]

to:

Attach:download.png [[Attach:dynamic_optimization_fishery.zip|Economic Optimization of Fishery in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/MA53XPp-a7I" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

----

!!!! Jennings Problem

Attach:download.png [[Attach:dynamic_optimization_jennings.zip|Jennings Problem in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/MA53XPp-a7I" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

----

!!!! Jennings Problem

Attach:download.png [[Attach:dynamic_optimization_jennings.zip|Jennings Problem in MATLAB and Python]]

Changed line 48 from:

<iframe width="560" height="315" src="https://www.youtube.com/embed/~~jB7WWGHFNIw~~" frameborder="0" allowfullscreen></iframe>

to:

<iframe width="560" height="315" src="https://www.youtube.com/embed/MA53XPp-a7I" frameborder="0" allowfullscreen></iframe>

Changed lines 41-49 from:

to:

----

!!!! Commercial Fishery

Attach:download.png [[Attach:dynamic_optimization_fishery.zip|Dynamic Optimization Fishery Solution in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/jB7WWGHFNIw" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

!!!! Commercial Fishery

Attach:download.png [[Attach:dynamic_optimization_fishery.zip|Dynamic Optimization Fishery Solution in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/jB7WWGHFNIw" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Added lines 28-29:

See [[https://youtu.be/5qY7WyngRbo|estimation example]] using the same model to explain estimator objectives.

Added line 26:

<iframe width="560" height="315" src="https://www.youtube.com/embed/cd0TkFtXfWs" frameborder="0" allowfullscreen></iframe>

Changed line 7 from:

!!!! Aly-Chan Problem'^2^'

to:

!!!! Aly-Chan Singular Control Problem'^2^'

Changed lines 21-24 from:

!!!! ~~Catalyzed Reaction~~

Attach:download.png [[Attach:~~dynamic_optimization_catalyst~~.~~zip|Dynamic Optimization Catalyst~~ Solution in MATLAB and Python]]

Attach:download.png [[

to:

!!!! Aly Singular Control Problem

Attach:download.png [[Attach:dynamic_optimization_aly.zip|Aly Singular Control Solution in MATLAB and Python]]

Attach:download.png [[Attach:dynamic_optimization_aly.zip|Aly Singular Control Solution in MATLAB and Python]]

Deleted line 25:

Added lines 27-38:

----

!!!! Catalyzed Reaction

Attach:download.png [[Attach:dynamic_optimization_catalyst.zip|Dynamic Optimization Catalyst Solution in MATLAB and Python]]

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/jB7WWGHFNIw" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Changed line 27 from:

to:

<iframe width="560" height="315" src="https://www.youtube.com/embed/jB7WWGHFNIw" frameborder="0" allowfullscreen></iframe>

Added lines 5-6:

----

Changed line 12 from:

to:

Added lines 17-27:

(:htmlend:)

----

!!!! Catalyzed Reaction

!!!! Solution to Catalyzed Reaction Problem

Attach:download.png [[Attach:dynamic_optimization_catalyst.zip|Dynamic Optimization Catalyst Solution in MATLAB and Python]]

(:html:)

----

!!!! Catalyzed Reaction

!!!! Solution to Catalyzed Reaction Problem

Attach:download.png [[Attach:dynamic_optimization_catalyst.zip|Dynamic Optimization Catalyst Solution in MATLAB and Python]]

(:html:)

Added lines 12-15:

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/tY8kyJq4BEY" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Changed line 5 from:

!!!! Aly-Chan ~~Problem~~

to:

!!!! Aly-Chan Problem'^2^'

Changed line 7 from:

* The objective is to minimize final state ''x_3_(pi/2)'' by adjusting the value of ''u''.

to:

* The objective is to minimize final state ''x'_3_'(pi/2)'' by adjusting the value of ''u''.

Changed lines 6-8 from:

* ~~Nonlinear, constrained, minimize final state~~

to:

* Solve the following nonlinear and constrained problem.

* The objective is to minimize final state ''x_3_(pi/2)'' by adjusting the value of ''u''.

* Compare to the exact solution of ''u(t)= -sin(t)''.

* The objective is to minimize final state ''x_3_(pi/2)'' by adjusting the value of ''u''.

* Compare to the exact solution of ''u(t)= -sin(t)''.

Added lines 1-17:

!!!! Exercise

'''Objective:''' Set up and solve several [[Attach:Dynamic_Optimization_Benchmarks.pdf|dynamic optimization benchmark problems]]. Create a program'^1^' to optimize and display the results. ''Estimated Time (each): 30 minutes''

!!!! Aly-Chan Problem

* Nonlinear, constrained, minimize final state

->Attach:dynopt_alychan.png

!!!! Solution to Aly-Chan Problem

Attach:download.png [[Attach:dynamic_optimization_alychan.zip|Dynamic Optimization Aly-Chan Solution in MATLAB and Python]]

----

!!!! References

# Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. [[http://dx.doi.org/10.1016/j.compchemeng.2014.04.013|Article]]

# Aly G.M. and Chan W.C. Application of a modified quasilinearization technique to totally singular optimal problems. International Journal of Control, 17(4): 809-815, 1973.

'''Objective:''' Set up and solve several [[Attach:Dynamic_Optimization_Benchmarks.pdf|dynamic optimization benchmark problems]]. Create a program'^1^' to optimize and display the results. ''Estimated Time (each): 30 minutes''

!!!! Aly-Chan Problem

* Nonlinear, constrained, minimize final state

->Attach:dynopt_alychan.png

!!!! Solution to Aly-Chan Problem

Attach:download.png [[Attach:dynamic_optimization_alychan.zip|Dynamic Optimization Aly-Chan Solution in MATLAB and Python]]

----

!!!! References

# Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. [[http://dx.doi.org/10.1016/j.compchemeng.2014.04.013|Article]]

# Aly G.M. and Chan W.C. Application of a modified quasilinearization technique to totally singular optimal problems. International Journal of Control, 17(4): 809-815, 1973.