Simulation of Dynamic Systems

Main.ModelSimulation History

Hide minor edits - Show changes to markup

February 16, 2024, at 06:55 PM by 10.35.117.248 -
Changed line 64 from:

$$\begin{bmatrix} y_1(t) \\ y_2(t) \\ \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 7.74 \\ \end{bmatrix} \begin{bmatrix} u(t) - u_w(t) \\ w(t) - w_w(t) \\ q(t) \\ \theta(t) \\ \end{bmatrix}$$

to:

$$\begin{bmatrix} y_1 \\ y_2 \\ \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 7.74 \\ \end{bmatrix} \begin{bmatrix} u - u_w \\ w - w_w \\ q \\ \theta \\ \end{bmatrix}$$

February 16, 2024, at 06:54 PM by 10.35.117.248 -
Changed lines 64-67 from:
to:

$$\begin{bmatrix} y_1(t) \\ y_2(t) \\ \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 7.74 \\ \end{bmatrix} \begin{bmatrix} u(t) - u_w(t) \\ w(t) - w_w(t) \\ q(t) \\ \theta(t) \\ \end{bmatrix}$$

Deleted lines 83-84:

from __future__ import division

February 16, 2024, at 06:51 PM by 10.35.117.248 -
Added lines 61-62:

$$\begin{bmatrix} \dot{u} \\ \dot{w} \\ \dot{q} \\ \dot{\theta} \\ \end{bmatrix} = \begin{bmatrix} -0.003 & 0.039 & 0 & -0.322 \\ -0.065 & -0.319 & 7.74 & 0 \\ 0.020 & -0.101 & -0.429 & 0 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix} \begin{bmatrix} u - u_w \\ w - w_w \\ q \\ \theta \\ \end{bmatrix} + \begin{bmatrix} 0.010 & 1 \\ -0.18 & -0.04 \\ -1.16 & 0.598 \\ 0 & 0 \\ \end{bmatrix} \begin{bmatrix} e \\ t \\ \end{bmatrix}$$

November 17, 2021, at 12:55 AM by 10.35.117.248 -
Changed lines 175-176 from:

plt.plot(m.time,u[0],'b-',linewidth=2.0) plt.plot(m.time,u[1],'g:',linewidth=2.0)

to:

plt.plot(m.time,u[0],'b-',lw=2.0) plt.plot(m.time,u[1],'g:',lw=2.0)

Changed line 181 from:

plt.plot(m.time,y[0],'r-',linewidth=2.0)

to:

plt.plot(m.time,y[0],'r-',lw=2.0)

Changed line 188 from:

plt.plot(m.time,y[1],'r-',linewidth=2.0)

to:

plt.plot(m.time,y[1],'r-',lw=2.0)

Added lines 80-82:
Changed line 86 from:

from gekko import SS

to:

from gekko import GEKKO

Changed line 113 from:
to:
Changed lines 123-124 from:

m,x,y,u = SS(A,B,C)

to:

m = GEKKO() x,y,u = m.state_space(A,B,C,D=None)

Deleted line 129:
Changed lines 163-170 from:
to:
  1. get additional solution information (trajectories)

import json with open(m.path+'//results.json') as f:

    results = json.load(f)
  1. get internal GEKKO variable names

air_speed = y[0].name climb_rate = y[1].name

Changed lines 175-176 from:

plt.plot(m.time,u[0],'r-',linewidth=2.0) plt.plot(m.time,u[1],'k:',linewidth=2.0)

to:

plt.plot(m.time,u[0],'b-',linewidth=2.0) plt.plot(m.time,u[1],'g:',linewidth=2.0)

Changed lines 181-183 from:

plt.plot(m.time,y[0],'b:',linewidth=2.0)

  1. plt.plot(m.time,y[0].tr_hi,'k-')
  2. plt.plot(m.time,y[0].tr_lo,'k-')
to:

plt.plot(m.time,y[0],'r-',linewidth=2.0) plt.plot(m.time,results[air_speed+'.tr_hi'],'k:') plt.plot(m.time,results[air_speed+'.tr_lo'],'k:')

Changed lines 185-186 from:
to:

plt.ylabel('Air Speed')

Changed lines 188-190 from:

plt.plot(m.time,y[1],'g--',linewidth=2.0)

  1. plt.plot(m.time,y[1].tr_hi,'k-')
  2. plt.plot(m.time,y[1].tr_lo,'k-')
to:

plt.plot(m.time,y[1],'r-',linewidth=2.0) plt.plot(m.time,results[climb_rate+'.tr_hi'],'k:') plt.plot(m.time,results[climb_rate+'.tr_lo'],'k:')

Added line 192:

plt.ylabel('Climb Rate')

January 28, 2018, at 06:27 AM by 174.148.61.237 -
Added lines 77-184:

(:toggle hide gekko button show="Show GEKKO (Python) Code":) (:div id=gekko:) (:source lang=python:) from __future__ import division

from gekko import SS import numpy as np

  1. Linear model of a Boeing 747
  1. Level flight at 40,000 ft elevation
  2. Velocity at 774 ft/sec (0.80 Mach)
  3. States
  4. u - uw (ft/sec) - horizontal velocity - horizontal wind
  5. w - ww (ft/sec) - vertical velocity - vertical wind
  6. q (crad/sec) - angular velocity
  7. theta (crad) - angle from horizontal
  8. note: crad = 0.01 rad
  9. Inputs
  10. e - elevator
  11. t - throttle
  12. Outputs
  13. u - uw (ft/sec) - horizontal airspeed
  14. hdot = -w + u0 * theta with u0 = 774 ft/sec

A = np.array([[-.003, 0.039, 0, -0.322],

              [-0.065, -0.319, 7.74, 0],
              [0.020, -0.101, -0.429, 0],
              [0, 0, 1, 0]])

B = np.array([[0.01, 1],

              [-0.18, -0.04],
              [-1.16, 0.598],
              [0, 0]])

C = np.array([[1, 0, 0, 0],

              [0, -1, 0, 7.74]])
  1. Build GEKKO State Space model

m,x,y,u = SS(A,B,C)

m.time = [0, 0.1, 0.2, 0.4, 1, 1.5, 2, 3, 4, 5, 6, 7, 8, 10, 12, 15] m.options.imode = 6 m.options.nodes = 3

  1. MV tuning
  1. lower and upper bounds for elevator pitch
  2. lower and upper bounds for thrust
  3. delta MV movement cost

for i in range(len(u)):

    u[i].lower = -5
    u[i].upper = 5
    u[i].dcost = 1
    u[i].status = 1
  1. CV tuning
  1. tau = first order time constant for trajectories

y[0].tau = 5 y[1].tau = 8

  1. tr_init = 0 (dead-band)
  2. = 1 (first order trajectory)
  3. = 2 (first order traj, re-center with each cycle)

y[0].tr_init = 2 y[1].tr_init = 2

  1. targets (dead-band needs upper and lower values)
  2. SPHI = upper set point
  3. SPLO = lower set point

y[0].sphi= -8.5 y[0].splo= -9.5 y[1].sphi= 5.4 y[1].splo= 4.6

y[0].status = 1 y[1].status = 1

m.solve()

  1. plot results

import matplotlib.pyplot as plt plt.figure(1) plt.subplot(311) plt.plot(m.time,u[0],'r-',linewidth=2.0) plt.plot(m.time,u[1],'k:',linewidth=2.0) plt.legend(['Elevator','Thrust']) plt.ylabel('MV Action')

plt.subplot(312) plt.plot(m.time,y[0],'b:',linewidth=2.0)

  1. plt.plot(m.time,y[0].tr_hi,'k-')
  2. plt.plot(m.time,y[0].tr_lo,'k-')

plt.legend(['Air Speed','Upper Trajectory','Lower Trajectory'])

plt.subplot(313) plt.plot(m.time,y[1],'g--',linewidth=2.0)

  1. plt.plot(m.time,y[1].tr_hi,'k-')
  2. plt.plot(m.time,y[1].tr_lo,'k-')

plt.legend(['Climb Rate','Upper Trajectory','Lower Trajectory'])

plt.show() (:sourceend:) (:divend:)

May 05, 2015, at 07:48 PM by 10.10.150.52 -
Added lines 73-76:

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

May 05, 2015, at 07:23 PM by 10.10.150.52 -
Changed line 60 from:

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed and climb rate. The model equations are shown below in state space form that relates elevator angle in centi-radians and thrust to four states including airspeed in the horizontal direction (u - u w), airspeed in the vertical direction (w - w w), rotation of the aircraft (q), and angle of the aircraft (theta).

to:

This exercise involves the simulation of a Boeing 747 airplane at a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed and climb rate. The model equations are shown below in state space form that relates elevator angle in centi-radians and thrust to four states including airspeed in the horizontal direction (u - u w), airspeed in the vertical direction (w - w w), rotation of the aircraft (q), and angle of the aircraft (theta).

May 05, 2015, at 12:10 AM by 10.5.113.199 -
Changed line 60 from:

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed and climb rate. The model equations are shown below in state space form that relates elevator angle in centi-radians and thrust to four states including airspeed in the horizontal direction (u'u w), airspeed in the vertical direction (w'w w), rotation of the aircraft (q), and angle of the aircraft (theta).

to:

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed and climb rate. The model equations are shown below in state space form that relates elevator angle in centi-radians and thrust to four states including airspeed in the horizontal direction (u - u w), airspeed in the vertical direction (w - w w), rotation of the aircraft (q), and angle of the aircraft (theta).

May 05, 2015, at 12:10 AM by 10.5.113.199 -
Changed lines 60-61 from:

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed and climb rate. The model equations are shown below in state space form that relates elevator angle in centi-radians and thrust to four states including airspeed in the horizontal direction (u'uw), airspeed in the vertical direction (w'ww), rotation of the aircraft (q), and angle of the aircraft (theta).

to:

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed and climb rate. The model equations are shown below in state space form that relates elevator angle in centi-radians and thrust to four states including airspeed in the horizontal direction (u'u w), airspeed in the vertical direction (w'w w), rotation of the aircraft (q), and angle of the aircraft (theta).

Changed line 66 from:

The wind speeds are given in the horizontal (uw) and vertical (ww) directions with a nominal velocity of the aircraft of u0=774 ft/sec (0.8 Mach speed). The output y1 is the air speed and y2 is the climb rate.

to:

The wind speeds are given in the horizontal (u w) and vertical (w w) directions with a nominal velocity of the aircraft of u0=774 ft/sec (0.8 Mach speed). The output y1 is the air speed and y2 is the climb rate.

May 05, 2015, at 12:07 AM by 10.5.113.199 -
Changed lines 66-67 from:

The wind speeds are given in the horizontal (uw) and vertical (ww) directions with a nominal velocity of the aircraft of u0=774 ft/sec (0.8 Mach speed).

to:

The wind speeds are given in the horizontal (uw) and vertical (ww) directions with a nominal velocity of the aircraft of u0=774 ft/sec (0.8 Mach speed). The output y1 is the air speed and y2 is the climb rate.

Simulate step responses of the aircraft with respect to the elevator angle and thrust. Design a model predictive controller to respond to set point changes in the air speed and climb rate of the aircraft. Explain the coordinated movement of the manipulated variables to achieve the desired set points of the controlled variables.

Changed line 72 from:

TBD

to:
May 05, 2015, at 12:00 AM by 10.5.113.199 -
Changed lines 60-61 from:

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed (u-uw) and climb rate (hrate).

to:

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed and climb rate. The model equations are shown below in state space form that relates elevator angle in centi-radians and thrust to four states including airspeed in the horizontal direction (u'uw), airspeed in the vertical direction (w'ww), rotation of the aircraft (q), and angle of the aircraft (theta).

Changed lines 64-65 from:
to:

The wind speeds are given in the horizontal (uw) and vertical (ww) directions with a nominal velocity of the aircraft of u0=774 ft/sec (0.8 Mach speed).

May 04, 2015, at 11:48 PM by 10.5.113.199 -
Changed lines 58-59 from:

flight_controls_747.png

to:
Changed line 62 from:

flight_equations_747.png

to:
May 04, 2015, at 11:48 PM by 10.5.113.199 -
Changed lines 56-57 from:

Exercise

to:

Exercise

flight_controls_747.png

This exercise involves the simulation of a Boeing 747 airplane at cruising a cruising altitude of 40,000 ft. In this application1, a model of the process is desired to relate the elevator (e) and thrust (t) to the airspeed (u-uw) and climb rate (hrate).

flight_equations_747.png

Solution

Changed lines 71-73 from:

Solution

TBD

to:

References

  1. Camacho, E.F. and Bordons, C., Model Predictive Control, 2nd Edition, Advanced Textbooks in Control and Signal Processing, Springer, 2004.
Changed lines 17-20 from:
  • Mass Balance
  • Species Balance
  • Energy Balance
  • Funnel (Mass Balance)
to:
  • Mass Balance Solution
  • Species Balance Solution
  • Energy Balance Solution
  • Funnel (Mass Balance) Solution
Deleted lines 47-52:

Exercise

Solution

Added lines 55-62:

Exercise

TBD

Solution

TBD

Deleted lines 12-13:

Develop and Solve Dynamic Equations

Added lines 17-27:
  • Mass Balance
  • Species Balance
  • Energy Balance
  • Funnel (Mass Balance)

Two numerical methods reviewed are sequential and simultaneous simulation techniques.

Sequential Simulation

Sequential simulation methods take successive time steps in the simulation horizon and often refine the size of each step to meet a specified error tolerance. Euler's method is the most basic method for sequential simulation while other methods generally offer improved accuracy and therefore allow larger step sizes.

Changed line 29 from:

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

to:

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

Changed line 33 from:

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

to:

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

Deleted lines 35-50:

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

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

Two numerical methods reviewed are sequential and simultaneous simulation techniques.

Sequential Simulation

Sequential simulation methods take successive time steps in the simulation horizon and often refine the size of each step to meet a specified error tolerance. Euler's method is the most basic method for sequential simulation while other methods generally offer improved accuracy and therefore allow larger step sizes.

(--video example with MATLAB / Python solvers)

Deleted lines 47-48:

(--include additional references--)

Changed lines 54-58 from:

(--video example with APM MATLAB / APM Python solvers)

(--video example with APM MATLAB / APM Python solvers)

(video of numerical solution, APM MATLAB, APM Python, APMonitor - show how error changes with refined discretization)

to:

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

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

Changed lines 11-14 from:

The DAE can be solved with a variety of numerical methods. Two numerical methods reviewed are sequential and simultaneous simulation techniques.

Sequential Simulation

to:

The DAE can be solved with a variety of analytic or numeric methods. Analytic approaches are possible for simple systems such as systems with one or two equations. Numeric methods are used with more complicated systems but these methods have approximation errors that may deviate from the exact solution. A first step in model development is to draw a schematic, list the assumptions, and write the differential and algebraic equations that describe the system.

Develop and Solve Dynamic Equations

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

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

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

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

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

Two numerical methods reviewed are sequential and simultaneous simulation techniques.

Sequential Simulation

Changed lines 43-44 from:

Simultaneous Simulation

to:

Simultaneous Simulation

Changed lines 57-61 from:

Exercise

Solution

to:

Exercise

Solution

Changed line 15 from:

Sequential simulation methods take successive time steps in the simulation horizon and often refine the size of each step to meet a specified error tolerance. Euler's method is the most basic method for sequential simulation while other methods like the higher order Runga Kutta techniques generally offer improved accuracy and therefore allow larger step sizes.

to:

Sequential simulation methods take successive time steps in the simulation horizon and often refine the size of each step to meet a specified error tolerance. Euler's method is the most basic method for sequential simulation while other methods generally offer improved accuracy and therefore allow larger step sizes.

Deleted lines 38-39:
Added lines 42-43:

(video of numerical solution, APM MATLAB, APM Python, APMonitor - show how error changes with refined discretization)

Changed lines 29-31 from:
 Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. Available at: https://dx.doi.org/10.1016/j.compchemeng.2014.04.013

(--include references--)

to:
  • Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. Available at: https://dx.doi.org/10.1016/j.compchemeng.2014.04.013

(--include additional references--)

Exercise

Solution

Changed line 29 from:
to:
 Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. Available at: https://dx.doi.org/10.1016/j.compchemeng.2014.04.013
Changed lines 5-6 from:

Simulation of dynamic systems is the process of finding a numerical solution to a set of differential and algebraic equations (DAEs) with given initial conditions (x0). A mathematical expression of an Initial Value Problem (IVP) is shown as a set of

to:

Simulation of dynamic systems is the process of finding a numerical solution to a set of differential and algebraic equations (DAEs) with given initial conditions (x0). A mathematical expression of an Initial Value Problem (IVP) is shown below.

Changed lines 9-35 from:
 Given x0 and p
to:
 Given x0 and p

The DAE can be solved with a variety of numerical methods. Two numerical methods reviewed are sequential and simultaneous simulation techniques.

Sequential Simulation

Sequential simulation methods take successive time steps in the simulation horizon and often refine the size of each step to meet a specified error tolerance. Euler's method is the most basic method for sequential simulation while other methods like the higher order Runga Kutta techniques generally offer improved accuracy and therefore allow larger step sizes.

(--video example with MATLAB / Python solvers)

Simultaneous Simulation

Simultaneous simulation methods are used to converge all of the state variable predictions together instead of one step at a time. Orthogonal collocation on finite elements is a popular method to convert the DAE into a Nonlinear Programming (NLP) problem for solution by efficient solvers.

 0 = f(x,p)
 0 < g(x,p)
 Given x0 and p

Further details on orthogonal collocation are provided at the following references.

(--include references--)

(--video example with APM MATLAB / APM Python solvers)

(--video example with APM MATLAB / APM Python solvers)

Added lines 4-9:

Simulation of dynamic systems is the process of finding a numerical solution to a set of differential and algebraic equations (DAEs) with given initial conditions (x0). A mathematical expression of an Initial Value Problem (IVP) is shown as a set of

 0 = f(dx/dt,x,p)
 0 < g(dx/dt,x,p)
 Given x0 and p
Added lines 1-3:

(:title Simulation of Dynamic Systems:) (:keywords simulation, sequential, simultaneous, ode solver, dae solver, modeling language, differential, algebraic, tutorial:) (:description Simmulation of Differential Algebraic Equations (DAEs) with use in dynamic simulation, estimation, and control:)