NLOptControl.jl¶
Table of Contents¶
Background Information¶
While detailed information on these approaches to discretizing infinite dimensional (or continuous) optimal control problems can be found (and comes from) this Ph.D. dissertation, this related journal publication and this technical report, the Background Information section will cover some basics.
Lagrange Interpolating Polynomials¶
Definition¶
- given \((N+1)\) unique data points
- \((x_0,y_0),(x_1,y_1),....,(x_N,y_N)\)
- we can create an \(N^{th}\) order Lagrange interpolating polynomial
- where,
- \[\begin{eqnarray} f(x_0) = y_0\\ f(x_1) = y_1\\ .\\ .\\ f(x_i) = y_i\\ .\\ f(x_N) = y_N \end{eqnarray}\]
So, we are just multiplying by the given \(y_i\) values.
Lagrange Basis Polynomials¶
More information on Lagrange Basis Polynomials is here
- so expanding this,
- \[\begin{eqnarray} \mathcal{L}_i(x) &=\frac{x-x_0}{x_i-x_0}\frac{x-x_1}{x_i-x_1}...\\ &...\frac{x-x_{i-1}}{x_i-x_{i-1}}...\\ &...\frac{x-x_{i+1}}{x_i-x_{i+1}}...\\ &...\frac{x-x_N}{x_i-x_N} \end{eqnarray}\]
Notice that we do not include the term where \(i==j\)!
Please see Functionality for details on implementation.
Direct Transcription of Optimal Control Problems¶
Let \(N_t+1\) be the total number of discrete time points.
Pseudospectral Methods¶
Change of Interval¶
To can change the limits of the integration (in order to apply Quadrature), we introduce \(\tau \in [-1,+1]\) as a new independent variable and perform a change of variable for \(t\) in terms of \(\tau\), by defining:
\[\tau = \frac{2}{t_{{N}_{t}}-t_0}t - \frac{t_{N_t}+t_0}{t_{N_t}-t_0}\]
Polynomial Interpolation¶
Select a set of \(N_t+1\) node points:
\[\mathbf{\tau} = [\tau_0,\tau_1,\tau_2,.....,\tau_{N_t}]\]
- These none points are just numbers
- Increasing and distinct numbers \(\in [-1,+1]\)
A unique polynomial \(P(\tau)\) exists (i.e. \(\exists! P(\tau)\)) of a maximum degree of \(N_t\) where:
\[f(\tau_k)=P(\tau_k),\;\;\;k={0,1,2,....N_t}\]
- So, the function evaluated at \(\tau_k\) is equivalent the this polynomial evaluated at that point.
But, between the intervals, we must approximate \(f(\tau)\) as:
\[f(\tau) \approx P(\tau)= \sum_{k=0}^{N_t}f(\tau_k)\phi_k(\tau)\]
with \(\phi_k(•)\) are basis polynomials that are built by interpolating \(f(\tau)\) at the node points.
Approximating Derivatives¶
We can also approximate the derivative of a function \(f(\tau)\) as:
With \(\mathbf{D}\) is a \((N_t+1)\times(N_t+1)\) differentiation matrix that depends on:
- values of \(\tau\)
- type of interpolating polynomial
Now we have an approximation of \(\dot{f}(\tau_k)\) that depends only on \(f(\tau)\)!
Approximating Integrals¶
The integral we are interested in evaluating is:
This can be approximated using quadrature:
where \(w_k\) are quadrature weights and depend only on:
- values of \(\tau\)
- type of interpolating polynomial
Legendre Pseudospectral Method¶
- Polynomial
Define an N order Legendre polynomial as:
\[L_N(\tau) = \frac{1}{2^NN!}\frac{\mathrm{d}^n}{\mathrm{d}\tau^N}(\tau^2-1)^N\]
- Nodes
- Differentiation Matrix
- Interpolating Polynomial Function
hp-psuedospectral method¶
To solve the integral constraints within the optimal control problem we employs the hp-pseudospectral method. The hp-psuedospectral method is an form of Gaussian Quadrature, which uses multi-interval collocation points.
Single Phase Optimal Control¶
Find:
- The state: \(\mathbf{x}(t)\)
- The control: \(\mathbf{u}(t)\)
- The integrals: \(\mathbf{q}\)
- The initial time: \(t_0\)
- The final time: \(t_f\)
- To Minimize:
- \[J = \Phi(\mathbf{x}(t_0),\mathbf{x}(t_f),\mathbf{q},t_0,t_f)\]
That Satisfy the Following Constraints:
- Dynamic Constraints:
\[\frac{\mathrm{d}\mathbf{x}}{\mathrm{d}t} = \mathbf{\psi}(\mathbf{x}(t),\mathbf{u}(t),t)\]
- Inequality Path Constraints:
\[\begin{split}\mathbf{c}_{min} <= \mathbf{c}(\mathbf{x}(t),\mathbf{u}(t),t) <= \mathbf{c}_{max}\end{split}\]
- Integral Constraints:
\[q_i = \int_{t_0}^{t_f} \Upsilon_i(\mathbf{x}(t),\mathbf{u}(t),t)\, \mathrm{d}t,\;\;(i=1,....,n_q)\]
- Event Constraints:
\[\begin{split}\mathbf{b}_{min} <= \mathbf{b}(\mathbf{x}(t_0),\mathbf{x}(t_f),t_f,\mathbf{q}) <= \mathbf{b}_{max}\end{split}\]
Change of Interval¶
To can change the limits of the integration (in order to apply Quadrature), we introduce \(\tau \in [-1,+1]\) as a new independent variable and perform a change of variable for \(t\) in terms of \(\tau\), by defining:
\[t = \frac{t_f - t_0}{2}\tau + \frac{t_f + t_0}{2}\]
The optimal control problem defined above (TODO: figure out equation references), is now redefined in terms of \(\tau\) as:
Find:
- The state: \(\mathbf{x}(\tau)\)
- The control: \(\mathbf{u}(\tau)\)
- The integrals: \(\mathbf{q}\)
- The initial time: \(t_0\)
- The final time: \(t_f\)
- To Minimize:
- \[J = \Phi(\mathbf{x}(-1),\mathbf{x}(+1),\mathbf{q},t_0,t_f)\]
That Satisfy the Following Constraints:
- Dynamic Constraints:
\[\frac{\mathrm{d}\mathbf{x}}{\mathrm{d}\tau} = \frac{t_f-t_0}{2} \mathbf{\psi}(\mathbf{x}(\tau),\mathbf{u}(\tau),\tau,t_0,t_f)\]
- Inequality Path Constraints:
\[\begin{split}\mathbf{c}_{min} <= \mathbf{c}(\mathbf{x}(\tau),\mathbf{u}(\tau),\tau,t_0,t_f) <= \mathbf{c}_{max}\end{split}\]
- Integral Constraints:
\[q_i = \frac{t_f-t_0}{2} \int_{-1}^{+1} \Upsilon_i(\mathbf{x}(\tau),\mathbf{u}(\tau),\tau,t_0,t_f)\, \mathrm{d}\tau,\;\;(i=1,....,n_q)\]
- Event Constraints:
\[\begin{split}\mathbf{b}_{min} <= \mathbf{b}(\mathbf{x}(-1),\mathbf{x}(+1),t_f,\mathbf{q}) <= \mathbf{b}_{max}\end{split}\]
Divide The Interval \(\tau \in [-1,+1]\)¶
- The interval \(\tau \in [-1,+1]\) is now divided into a mesh of K mesh intervals as:
- \[[T_{k-1},T_k], k = 1,...,T_K\]
- with \((T_0,...,T_K)\) being the mesh points; which satisfy:
- \[\begin{split}-1 = T_0 < T_1 < T_2 < T_3 < ........... < T_{K-1} < T_K = T_f = +1\end{split}\]
Rewrite the Optimal Control Problem using the Mesh¶
Find:
- The state : \(\mathbf{x}^{(k)}(\tau)\) in mesh interval k
- The control: \(\mathbf{u}^{(k)}(\tau)\) in mesh interval k
- The integrals: \(\mathbf{q}\)
- The initial time: \(t_0\)
- The final time: \(t_f\)
- To Minimize:
- \[J = \Phi(\mathbf{x}^{(1)}(-1),\mathbf{x}^{(K)}(+1),\mathbf{q},t_0,t_f)\]
That Satisfy the Following Constraints:
- Dynamic Constraints:
\[\frac{\mathrm{d}\mathbf{x}^{(k)}(\tau^{(k)})}{\mathrm{d}\tau^{(k)}} = \frac{t_f-t_0}{2} \mathbf{\psi}(\mathbf{x}^{(k)}(\tau^{(k)}),\mathbf{u}^{(k)}(\tau^{(k)}),\tau^{(k)},t_0,t_f),\;\;(k=1,...,K)\]
- Inequality Path Constraints:
- Integral Constraints:
- Event Constraints:
State Continuity
Also, we must now constrain the state to be continuous at each interior mesh point \((T_1,...T_{k-1})\) by enforcing:
\[\mathbf{y}^{k}(T_k) = \mathbf{y}^{k+1}(T_k)\]
Optimal Control Problem Approximation¶
The optimal control problem will now be approximated using the Radau Collocation Method as which follows the description provided by [BGar11]. In collocation methods, the state and control are discretized at particular points within the selected time interval. Once this is done the problem can be transcribed into a nonlinear programming problem (NLP) and solved using standard solvers for these types of problems, such as IPOPT or KNITRO.
- For each mesh interval \(k\in[1,..,K]\):
- \[\begin{eqnarray} \mathbf{x}^{(k)}(\tau)&\approx\mathbf{X}^{(k)}(\tau)=\displaystyle\sum_{j=1}^{N_k+1}\mathbf{X}_j^{(k)}\frac{\mathrm{d}\mathcal{L}_j^{k}(\tau)}{\mathrm{d}\tau}\\ where,\;\;&\\ \mathcal{L}_j^{k}(\tau)&=\prod_{\substack{l=1 \\ l\neq j}}^{N_k+1}\frac{\tau-\tau_l^{(k)}}{\tau_j^{(k)}-\tau_l^{(k)}}\\ and,\;\;&\\ &D_{ki}=\dot{\mathcal{L}}_i(\tau_k)=\frac{\mathrm{d}\mathcal{L}_j^{k}(\tau)}{\mathrm{d}\tau} \end{eqnarray}\]
- also,
\(\mathcal{L}_j^{(k)}(\tau),\;\;(j=1,...,N_k+1)\) is a basis of Lagrange polynomials
\((\tau_1^{k},.....,\tau_{N_k}^{(k)})\) are the Legendre-Gauss-Radau collocation points in mesh interval k
- defined on the subinterval \(\tau^{(k)}\in[T_{k-1},T_k]\)
- \(\tau_{N_k+1}^{(k)}=T_k\) is a noncollocated point
A basic description of Lagrange Polynomials is presented in Lagrange Interpolating Polynomials
- The \(\mathbf{D}\) matrix:
- Has a size \(= [N_c]\times[N_c+1]\)
with \((1<=k<=N_c), (1<=i<=N_c+1)\)
- this non-square shape because the state approximation uses the \(N_c+1\) points:
\((\tau_1,...\tau_{N_c+1})\)
- but collocation is only done at the \(N_c\) LGR points:
\((\tau_1,...\tau_{N_c})\)
If we define the state matrix as:
The dynamics are collocated at the \(N_c\) LGR points using:
\(\mathbf{D}_k\mathbf{X}^{LGR} = \frac{(t_f-t_0)}{2}\mathbf{f}(\mathbf{X}_k,\mathbf{U}_k,\tau,t_0,t_f)\;\;for\;\;k = {1,...,Nc}\)
- with,
- \(\mathbf{D}_k\) being the \(k^{th}\) row of the \(\mathbf{D}\) matrix.
References
[BGar11] | Divya Garg. Advances in global pseudospectral methods for optimal control. PhD thesis, University of Florida, 2011. |
Package Functionality¶
Code Development¶
Approximation of Optimal Control Problem¶
Completed Functionality¶
The basic description of this functionality is detailed here Lagrange Interpolating Polynomials
The Lagrange basis polynomial equations where turned into a function.
The interpolation functionality was pushed to a lower level. This allows the user to easily use code to interpolate a polynomial.
The development of these function can be:
- Viewed remotely on using the jupyter nbviewer.
- Viewed locally and interacted using IJulia
To do this in julia type:
using IJulia notebook(dir=Pkg.dir("NLOptControl/examples/LIP/lagrange_basis_poly_dev"))
In this first example, we demonstrate the functionality using the interpolating functionality.
- where:
- \[y(x) = x^2\]
and the interval from x=1
to x=3
- with:
N = 2; # number of collocation points
- where:
- \[y(x) = x^3\]
and the interval from x=1
to x=3
- with:
N = 2; # number of collocation points

- Conclusions
- Each scaled Lagrange polynomial passes through a control point
- The final interpolating polynomial passes through each control point and is exact
This example investigates Runge’s phenomena.
- where:
- \[y(x) = \frac{1}{1+25x^2}\]
and the interval from x0=-1
to xf=1
- with:
N = order of Lagrange Polynomial x_data = linspace(x0,xf,N+1);

- Conclusions
- Be careful not to use too high of an
N
- Be careful not to use too high of an
These examples can be:
- Viewed remotely on using the jupyter nbviewer.
- Viewed locally and interacted using IJulia
To do this in julia type:
using IJulia notebook(dir=Pkg.dir("NLOptControl/examples/LIP/"))
The code developed in this package uses the Legendre-Pseudospectral Method with Lagrange-Gauss-Lobatto (LGL) nodes. A basic description of this implementation presented in this documentation at Pseudospectral Methods and more much more detailed information can be found in both [ASTW11] and [AHer15].
- In these examples we use:
- Legendre-Gauss-Lobatto (LGL) nodes
- Single interval approximations
- Approximate integrals in the range of
[-1,1]
- Approximate derivatives in the range of
[-1,1]
- These examples can be:
Viewed remotely on using the jupyter nbviewer.
Viewed locally and interacted using IJulia
To do this in julia type:
using IJulia notebook(dir=Pkg.dir("NLOptControl/examples/LGL_SI/"))
In the first example, we borrow a problem from Wikipedia.
- where:
- \[y(x) = 7x^3-8x^2-3x+3\]

- Conclusions
- We are able to exactly determine the integral
References
[BHer15] | Daniel Ronald Herber. Basic implementation of multiple-interval pseudospectral methods to solve optimal control problems. UIUC-ESDL-2015-01, 2015. |
[BSTW11] | Jie Shen, Tao Tang, and Li-Lian Wang. Spectral methods: algorithms, analysis and applications. Volume 41. Springer Science & Business Media, 2011. |
In the second example, we increase the order of the polynomial from 3
to 7
. Then we increase N
until we achieve accurate enough results.
- where:
- \[y(x) = 7x^7-8x^6 - 3x^5 + 3x^4 + 7x^3-8x^2-3x+3\]



- We are able to determine the integral very accurately when we increase N to 4
In the third example, we approximate the derivative of a function by Approximating Derivatives.
In this test:

- We are able to determine the derivative exactly when they are linear functions is \(N = 3\)
In this test we increase the order of y(x)
to:

- When the derivative function becomes nonlinear
- We can no longer calculate it exactly everywhere
- There are only \(N_{t+1} = 4\) node points
- To calculate the derivative exactly we would need an \(∞\) amount of \(N_{t+1}\)
- We are still calculating the integral exactly and should be able to with \(N = 3\) until \(x^5\)
In this test we increase the order of y(x)
to:

- We are still calculating the integral exactly and should be able to with \(N = 3\) until \(x^5\)
In this test we increase the order of y(x)
to:

- We are still calculating the integral exactly with \(N = 3\)!!
- The percent error is = 0.000000000000000000 %
In this test we increase the order of y(x)
to:

- As expected, we are not still calculating the integral exactly with \(N = 3\)!!
- The percent error is = -1.818181818181822340 %
References
[AHer15] | Daniel Ronald Herber. Basic implementation of multiple-interval pseudospectral methods to solve optimal control problems. UIUC-ESDL-2015-01, 2015. |
[ASTW11] | Jie Shen, Tao Tang, and Li-Lian Wang. Spectral methods: algorithms, analysis and applications. Volume 41. Springer Science & Business Media, 2011. |
The code developed here uses the Legendre-Pseudospectral Method with Legendre-Gauss-Radau (LGR) nodes. This example demonstrates using the LGR points to calculate the integral and the derivative of a known polynomial function. It can be seen, that it behaves as expected. One, major difference between LGR and LGL is that the LGR method does NOT use both endpoints, in fact the LGR method omits the final end point. Researchers at the University of Florida describe this method in many papers including [A1][A2][A3][A4].
- In these examples we use:
- Legendre-Gauss-Lobatto (LGR) nodes
- Single interval approximations
- Approximate integrals in the range of
[x0,xf]
- Approximate derivatives in the range of
[x0,xf]
- These examples can be:
Viewed remotely on using the jupyter nbviewer.
Viewed locally and interacted using IJulia
To do this in julia type:
using IJulia notebook(dir=Pkg.dir("NLOptControl/examples/LGR_SI/"))
References
[A1] | Christopher L Darby. hp–Pseudospectral Method for Solving Continuous-Time Nonlinear Optimal Control Problems. PhD thesis, University of Florida, 2011. |
[A2] | Divya Garg. Advances in global pseudospectral methods for optimal control. PhD thesis, University of Florida, 2011. |
[A3] | Divya Garg, Michael Patterson, William W Hager, Anil V Rao, David A Benson, and Geoffrey T Huntington. A unified framework for the numerical solution of optimal control problems using pseudospectral methods. Automatica, 46(11):1843–1851, 2010. |
[A4] | Divya Garg, Michael A Patterson, William W Hager, Anil V Rao, David A Benson, and Geoffrey T Huntington. An overview of three pseudospectral methods for the numerical solution of optimal control problems. Advances in the Astronautical Sciences, 135(1):475–487, 2009. |
Now, using Legendre-Gauss-Radau (LGR) points with multiple intervals to calculate the integral and the derivative of a known polynomial function. This example demonstrates using the Legendre-Gauss-Radau (LGR) points to calculate the integral and the derivative of a known polynomial function using a multiple interval approach.
NOTE: this is not an exhaustive list and there are help notes for most functions, that can be easily seen by typing:
julia>? # then press enter and type
# the name of the function of interest
- In these examples we use:
- Legendre-Gauss-Radau (LGR) nodes
- Multiple interval approximations
- Approximate integrals in the range of
[x0,xf]
- Approximate derivatives in the range of
[x0,xf]
In this first example, we demonstrate the functionality using LGR nodes
- where:
- \[y(x) = -3x^5+3x^4+7x^3-8x^2-3x+3\]
- with:
Nc = Int64(10); # number of collocation points in each interval Ni = Int64(4); # number of intervals

- with:
Nc = Int64(3); # number of collocation points in each interval Ni = Int64(2); # number of intervals

- with:
Nc = Int64(4); # number of collocation points in each interval Ni = Int64(2); # number of intervals

Conclusions
It seems, that using the multiple interval formulation sacrifices the property where
- We can calculate a
Pth
order polynomial exactly with \(2*N-2\) collocation points - We do not approximate a
5th
order polynomial with6
total collocation points - Looking at Test 1c, we can see that when we use
N=4
we calculate the intergral exactly- So the property applies only to each interval
- We can calculate a
Test 1b and Test 1c both show that we are not calculating the end point
In the previous example, we neglected the approximation of the final state in each interval \(Y^(k)(τ)\).
In this example, we will demonstrate calculation of this state.
- where:
- \[y(x) = 3x^2-3x+3\]
- with:
Nc = Int64(3); # number of collocation points in each interval Ni = Int64(2); # number of intervals

In this example, the state derivative at the end of each mesh.
- where:
- \[y(x) = -0.3x^2+3x-0.3\]
- with:
Nc = Int64(3); # number of collocation points in each interval Ni = Int64(2); # number of intervals

Now, we will look at the \(\mathbf{D}\) matrix used to calculate the derivatives above:
D =
4×4×2 Array{Float64,3}:
[:, :, 1] =
-1.0 1.50639 -1.10639 0.6
-0.210639 -0.155051 0.713568 -0.347878
0.0506395 -0.233568 -0.644949 0.827878
-0.0666667 0.276429 -2.00976 1.8
[:, :, 2] =
-1.0 1.50639 -1.10639 0.6
-0.210639 -0.155051 0.713568 -0.347878
0.0506395 -0.233568 -0.644949 0.827878
-0.0666667 0.276429 -2.00976 1.8
Notice that for each interval the \(\mathbf{D}\) matrix is actually identical. This is quite an interesting observation indeed, because different inputs where used to calculate it, these are the nodes.
For the first interval:
0.0
1.77526
4.22474
5.0
For the second interval:
5.0
6.77526
9.22474
10.0
These nodes depend on the interval \(t_0->t_f\) as well as the \(\tau\):
-1.0
-0.289898
0.689898
Which are the LGR nodes when \(N_c=3\)
So, it seems that maybe we can calculate the weights beforehand as well as the \(\mathbf{D}\) matrix and cache the result.
For the purposes of using this method for control, again we do not need to calculate the derivative of the state at the ends of each mesh. So, we can remove the bottom row of the \(\mathbf{D}\) matrix as:
D =
[:, :, 1] =
-1.0 1.50639 -1.10639 0.6
-0.210639 -0.155051 0.713568 -0.347878
0.0506395 -0.233568 -0.644949 0.827878
[:, :, 2] =
-1.0 1.50639 -1.10639 0.6
-0.210639 -0.155051 0.713568 -0.347878
0.0506395 -0.233568 -0.644949 0.827878

So, at the end of each mesh grid, we still approximate the state, but neglect it’s derivative.
References
[DGar11] | Divya Garg. Advances in global pseudospectral methods for optimal control. PhD thesis, University of Florida, 2011. |
In this example, we are working on preparing the code for use with optimization by creating higher level functionality. Examine the IJulia notebook to see differences in code.
- where:
- \[y(x) = -0.3x^2+3x-0.3\]
- with:
Nc = Int64(3); # number of collocation points in each interval Ni = Int64(2); # number of intervals

- These examples can be:
Viewed remotely on using the jupyter nbviewer.
Viewed locally and interacted using IJulia
To do this in julia type:
using IJulia notebook(dir=Pkg.dir("NLOptControl/examples/LGR_MI/"))
References
[CDar11] | Christopher L Darby. hp–Pseudospectral Method for Solving Continuous-Time Nonlinear Optimal Control Problems. PhD thesis, University of Florida, 2011. |
[CGar11] | Divya Garg. Advances in global pseudospectral methods for optimal control. PhD thesis, University of Florida, 2011. |
[CGPH+10] | Divya Garg, Michael Patterson, William W Hager, Anil V Rao, David A Benson, and Geoffrey T Huntington. A unified framework for the numerical solution of optimal control problems using pseudospectral methods. Automatica, 46(11):1843–1851, 2010. |
[CGPH+09] | Divya Garg, Michael A Patterson, William W Hager, Anil V Rao, David A Benson, and Geoffrey T Huntington. An overview of three pseudospectral methods for the numerical solution of optimal control problems. Advances in the Astronautical Sciences, 135(1):475–487, 2009. |
Here we are developing software to set up and keep track of all of the variables in the problem.
- To initialize the problem
To use:
using NLOptControl
ps, nlp = initialize_NLP(numStates=1,numControls=1,Ni=2,Nck=[2,3]);
ps = pseudospectral method related data:
NLOptControl.PS_data
Nck: [2,3]
Ni: 2
τ: Array{Float64,1}[[-1.0,0.333333],[-1.0,-0.289898,0.689898]]
ts: Array{Float64,1}[[-0.0,0.0],[-0.0,-0.0,0.0]]
ω: Array{Float64,1}[[0.5,1.5],[0.222222,1.02497,0.752806]]
ωₛ: Array{Float64,1}[[0.0,0.0],[0.0,0.0,0.0]]
t0: 0.0
tf: 0.0
DMatrix: Array{Float64,2}[[0.0 0.0 0.0; 0.0 0.0 0.0],[0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0]]
IMatrix: Array{Float64,2}[[0.0 0.0; 0.0 0.0],[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]]
stateMatrix: Array{Float64,2}[[0.0; 0.0; 0.0],[0.0; 0.0; 0.0; 0.0]]
controlMatrix: Array{Float64,2}[[0.0; 0.0],[0.0; 0.0; 0.0]]
nlp = nonlinear programming problem related data:
NLOptControl.NLP_data
numStates: 1
numControls: 1
numStatePoints: [3,4]
numControlPoints: [2,3]
lengthStateVector: 7
lengthControlVector: 5
lengthDecVector: 14
timeStartIdx: 13
timeStopIdx: 14
stateIdx: Tuple{Int64,Int64}[(1,3),(4,7)]
controlIdx: Tuple{Int64,Int64}[(8,9),(10,12)]
stateIdx_all: Tuple{Int64,Int64}[(-99,-99)]
controlIdx_all: Tuple{Int64,Int64}[(-99,-99)]
stateIdx_st: Tuple{Int64,Int64}[(-99,-99)]
controlIdx_ctr: Tuple{Int64,Int64}[(-99,-99)]
decisionVector: [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
- Lots of zeros right now because we still have a lot of initializing to do.
- numControls and numStates can both be greater than 1.
- The value of Ni must match the length of Nck
- Generating some data to play with is useful:
- Turning the nonlinear-programming problem into an optimal control problem
- This function basically takes a large design variable an sorts it back into the original variables
Approximates integral.
To use this function with Gaussian Quadrature (the default method):
ζ, approx_int_st = integrate_state(ps,nlp)
To use this function with the LGRIM:
integrate_state(ps,nlp;(:mode=>:LGRIM))
- In these examples we use:
- Demonstrate functionality to setup optimal control problem
- Also include the development scripts of these functions
- There is not a webpage for all examples, but the interested user can check out them out using IJulia
In this example, we are continuing to work on preparing the code for use with optimization by creating higher level functionality. Examine the IJulia notebook to see code.
Aside from using the new data structures we demonstrate:
- Using the integration matrix for the first time
- Using the higher level functionality
- where:
- \[y(x) = -0.3x^2+3x-0.3\]
with:
ps, nlp = initialize_NLP(numStates=1,numControls=1,Ni=3,Nck=[2,3,5]);

with:
ps, nlp = initialize_NLP(numStates=1,numControls=1,Ni=5,Nck=[200,3,100,5,100]);

In this example, we are going to approximate the 5th order Taylor series polynomial for sin() and cos() expanded about x=0.
- where:
- \[sin(x) ≈ P_5(x) = x - \frac{x^3}{3!} + \frac{x^5}{5!}\]\[cos(x) ≈ P_5(x) = 1 - \frac{x^2}{2!} + \frac{x^4}{4!}\]
and:
t0 = Float64(0); tf = Float64(2);
- These examples can be:
Viewed remotely on using the jupyter nbviewer.
Viewed locally and interacted using IJulia
To do this in julia type:
using IJulia notebook(dir=Pkg.dir("NLOptControl/examples/NLP2OCP/"))
References
Developing Code¶
This site documents current progress and functionality that is being developed.
This is for documentation that was created where something was still being worked on where:
- Everything was not working as expected, but has now been fixed or is obsolete.
- Removed Functionality
Bibliography¶
http://docs.juliadiffeq.org/latest/tutorials/ode_example.html#In-Place-Updates-1
https://github.com/JuliaDiffEq/ParameterizedFunctions.jl#ode-macros
http://docs.juliadiffeq.org/latest/tutorials/ode_example.html#Defining-Systems-of-Equations-Using-ParameterizedFunctions.jl-1 @ChrisRackauckas after looking at ParameterizedFunctions.jl, I realized that I have many many parameters and I it would be too much to write them all after the ‘’end’’ is there a way that I can include a “parameters.jl” file to execute this? Also, I am currently automatic differentiation, and I noticed that currently ParameterizedFunctions.jl uses symbolic differentiation. I remember you mentioning that you use automatic differentiation, can this also