Integral Objective (Luus)

Main.IntegralObjective History

Hide minor edits - Show changes to markup

March 27, 2023, at 05:46 PM by 10.35.117.248 -
Changed lines 36-40 from:

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

to:
November 17, 2021, at 12:52 AM by 10.35.117.248 -
Changed lines 77-79 from:

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,u.value,'r--',LineWidth=2,label=r'$u$')

to:

plt.plot(m.time,x1.value,'k-',lw=2,label=r'$x_1$') plt.plot(m.time,x2.value,'b-',lw=2,label=r'$x_2$') plt.plot(m.time,u.value,'r--',lw=2,label=r'$u$')

Changed lines 120-122 from:

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,u.value,'r--',LineWidth=2,label=r'$u$')

to:

plt.plot(m.time,x1.value,'k-',lw=2,label=r'$x_1$') plt.plot(m.time,x2.value,'b-',lw=2,label=r'$x_2$') plt.plot(m.time,u.value,'r--',lw=2,label=r'$u$')

December 23, 2019, at 08:43 PM by 136.36.211.159 -
Changed line 87 from:

(:toggle hide gekko2 button show="GEKKO (Python) Solution 2: m.integral":)

to:

(:toggle hide gekko2 button show="GEKKO (Python) Solution 2":)

Added line 90:
  1. this solution uses the m.integral function and produces the same answer
December 23, 2019, at 08:42 PM by 136.36.211.159 -
Changed lines 44-45 from:

(:toggle hide gekko button show="GEKKO (Python) Solution":) (:div id=gekko:)

to:

(:toggle hide gekko1 button show="GEKKO (Python) Solution 1":) (:div id=gekko1:)

Added lines 71-112:

m.options.IMODE = 6 m.solve()

  1. m.solve(remote=False) # for local solve

plt.figure(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,u.value,'r--',LineWidth=2,label=r'$u$') plt.legend(loc='best') plt.xlabel('Time') plt.ylabel('Value') plt.show() (:sourceend:) (:divend:)

(:toggle hide gekko2 button show="GEKKO (Python) Solution 2: m.integral":) (:div id=gekko2:) (:source lang=python:) import numpy as np import matplotlib.pyplot as plt from gekko import GEKKO

m = GEKKO()

nt = 101 m.time = np.linspace(0,2,nt)

  1. Variables

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

p = np.zeros(nt) p[-1] = 1.0 final = m.Param(value=p)

  1. Equations

m.Equation(x1.dt()==u) x2 = m.Intermediate(m.integral(0.5*x1**2))

  1. Objective Function

m.Obj(m.integral(0.5*x1**2)*final)

Added lines 86-89:

(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/23cTqkkJbIU" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> (:htmlend:)

Changed lines 44-85 from:
to:

(:toggle hide gekko button show="GEKKO (Python) Solution":) (:div id=gekko:) (:source lang=python:) import numpy as np import matplotlib.pyplot as plt from gekko import GEKKO

m = GEKKO()

nt = 101 m.time = np.linspace(0,2,nt)

  1. Variables

x1 = m.Var(value=1) x2 = m.Var(value=0) u = m.Var(value=0,lb=-1,ub=1)

p = np.zeros(nt) p[-1] = 1.0 final = m.Param(value=p)

  1. Equations

m.Equation(x1.dt()==u) m.Equation(x2.dt()==0.5*x1**2)

  1. Objective Function

m.Obj(x2*final)

m.options.IMODE = 6 m.solve()

  1. m.solve(remote=False) # for local solve

plt.figure(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,u.value,'r--',LineWidth=2,label=r'$u$') plt.legend(loc='best') plt.xlabel('Time') plt.ylabel('Value') plt.show() (:sourceend:) (:divend:)

Changed line 9 from:

$$\min_u \frac{1}{2} \int_0^2 x_1(t) \, dt$$

to:

$$\min_u \frac{1}{2} \int_0^2 x_1^2(t) \, dt$$

Changed lines 17-18 from:

$$x_2 = \frac{1}{2} \int_0^2 x_1(t) \, dt$$

to:

$$x_2 = \frac{1}{2} \int_0^2 x_1^2(t) \, dt$$

Changed line 24 from:

$$\frac{dx_2}{dt} = \frac{1}{2} x_1(t)$$

to:

$$\frac{dx_2}{dt} = \frac{1}{2} x_1^2(t)$$

Changed line 30 from:

The initial condition of the integral starts at zero and becomes the integral in the time range of 0 to 2 at the final point for the optimal control problem.

to:

The initial condition of the integral starts at zero and becomes the integral in the time range of 0 to 2. The value that is minimized is at the final point in the time horizon of the optimal control problem.

Changed line 12 from:

$$x(0) = 1$$

to:

$$x_1(0) = 1$$

Changed lines 25-26 from:

$$x(0) = 1$$

to:

$$x_1(0) = 1$$ $$x_2(0) = 0$$

Added lines 29-30:

The initial condition of the integral starts at zero and becomes the integral in the time range of 0 to 2 at the final point for the optimal control problem.

Changed line 17 from:

$$x_2 = \frac{1}{2} \int_0^2 x(t) \, dt$$

to:

$$x_2 = \frac{1}{2} \int_0^2 x_1(t) \, dt$$

Changed line 24 from:

{$\frac{dx_2}{dt} = \frac{1}{2} x_1(t)

to:

$$\frac{dx_2}{dt} = \frac{1}{2} x_1(t)$$

Added lines 1-49:

(:title Integral Objective (Luus):) (:keywords nonlinear control, Luus, optimal control, dynamic optimization, engineering optimization, MATLAB, Python, GEKKO, optimization suite:) (:description Luus optimal control problem solved with MATLAB, Python, and GEKKO.:)

Objective: Set up and solve the Luus optimal control benchmark problem. Create a program to optimize and display the results. Estimated Time: 30 minutes

The Luus optimal control problem has an integral objective function. Integrals are a natural expression of many systems where the accumulation of a quantity is maximized or minimized.

$$\min_u \frac{1}{2} \int_0^2 x_1(t) \, dt$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=u$$ $$x(0) = 1$$ $$-1 \le u(t) \le 1$$

Integral expressions are reformulated in differential and algebraic form by defining a new variable.

$$x_2 = \frac{1}{2} \int_0^2 x(t) \, dt$$

The new variable and integral are differentiated and included as an additional equation. The problem then becomes a minimization of the new variable `x_2` at the final time.

$$\min_u x_2\left(t_f\right)$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=u$$ {$\frac{dx_2}{dt} = \frac{1}{2} x_1(t) $$x(0) = 1$$ $$t_f = 2$$ $$-1 \le u(t) \le 1$$

Solutions


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



References

  1. Beal, L., GEKKO for Dynamic Optimization, 2018, URL: https://gekko.readthedocs.io/en/latest/
  2. 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. Article