Skip to content

Commit

Permalink
renamed function and updated to be compatible with newer version of I…
Browse files Browse the repository at this point in the history
…VP Solver Toolbox
  • Loading branch information
tamaskis committed Aug 29, 2022
1 parent b3f6108 commit 6b9c9c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
Binary file modified EXAMPLES.mlx
Binary file not shown.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `odericcati` [![View Solution of the Riccati Differential Equation (odericcati) on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/104030-solution-of-the-riccati-differential-equation-odericcati)
# `solve_riccati_ode` [![View Solution of the Riccati Differential Equation (odericcati) on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/104030-solution-of-the-riccati-differential-equation-odericcati)

Solves the Riccati differential equation for the finite-horizon linear quadratic regulator.

Expand All @@ -7,15 +7,15 @@ Solves the Riccati differential equation for the finite-horizon linear quadratic

## Syntax

`[t,P] = odericcati(A,B,Q,R,[],PT,tspan)`\
`[t,P] = odericcati(A,B,Q,R,S,PT,tspan)`
`[t,P] = solve_riccati_ode(A,B,Q,R,[],PT,tspan)`\
`[t,P] = solve_riccati_ode(A,B,Q,R,S,PT,tspan)`


## Description

`[t,P] = odericcati(A,B,Q,R,[],PT,tspan)` solves the Riccati differential equation <img src="https://latex.codecogs.com/svg.latex?\inline&space;\dot{\mathbf{P}}=-\left[\mathbf{A}^{T}\mathbf{P}+\mathbf{P}\mathbf{A}-(\mathbf{P}\mathbf{B}+\mathbf{S})\mathbf{R}^{-1}(\mathbf{B}^{T}\mathbf{P}+\mathbf{S}^{T})+\mathbf{Q}\right]" title="" /> for <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{P}(t)\in\mathbb{R}^{{n}\times{n}}" title="" />, given the state matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{A}\in\mathbb{R}^{{n}\times{n}}" title="" />, input matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{B}\in\mathbb{R}^{{n}\times{m}}" title="" />, state weighting matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{Q}\in\mathbb{R}^{{n}\times{n}}" title="" />, input weighting matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{R}\in\mathbb{R}^{{m}\times{m}}" title="" />, terminal condition <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{P}_{T}\in\mathbb{R}^{{n}\times{n}}" title="" />, and the time span `tspan` over which to solve. `tspan` can be specified either as the 1×2 double `[t0,T]` where <img src="https://latex.codecogs.com/svg.latex?\inline&space;t=t_{0}" title="" /> is the initial time and <img src="https://latex.codecogs.com/svg.latex?\inline&space;t=T" title="" /> is the final time, or as a 1×(N+1) vector of times `[t0,t1,...,tNminus1,T]` at which to return the solution for <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{P}(t)" title="" />. It is assumed that the cross-coupling weighting matrix is <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{S}=\mathbf{0}_{{n}\times{m}}" title="" />.
`[t,P] = solve_riccati_ode(A,B,Q,R,[],PT,tspan)` solves the Riccati differential equation <img src="https://latex.codecogs.com/svg.latex?\inline&space;\dot{\mathbf{P}}=-\left[\mathbf{A}^{T}\mathbf{P}+\mathbf{P}\mathbf{A}-(\mathbf{P}\mathbf{B}+\mathbf{S})\mathbf{R}^{-1}(\mathbf{B}^{T}\mathbf{P}+\mathbf{S}^{T})+\mathbf{Q}\right]" title="" /> for <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{P}(t)\in\mathbb{R}^{{n}\times{n}}" title="" />, given the state matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{A}\in\mathbb{R}^{{n}\times{n}}" title="" />, input matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{B}\in\mathbb{R}^{{n}\times{m}}" title="" />, state weighting matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{Q}\in\mathbb{R}^{{n}\times{n}}" title="" />, input weighting matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{R}\in\mathbb{R}^{{m}\times{m}}" title="" />, terminal condition <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{P}_{T}\in\mathbb{R}^{{n}\times{n}}" title="" />, and the time span `tspan` over which to solve. `tspan` can be specified either as the 1×2 double `[t0,T]` where <img src="https://latex.codecogs.com/svg.latex?\inline&space;t=t_{0}" title="" /> is the initial time and <img src="https://latex.codecogs.com/svg.latex?\inline&space;t=T" title="" /> is the final time, or as a 1×(N+1) vector of times `[t0,t1,...,tNminus1,T]` at which to return the solution for <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{P}(t)" title="" />. It is assumed that the cross-coupling weighting matrix is <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{S}=\mathbf{0}_{{n}\times{m}}" title="" />.

`[t,P] = odericcati(A,B,Q,R,S,PT,tspan)` does the same as the syntax above, but this time the cross-coupling weighting matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{S}\in\mathbb{R}^{{n}\times{m}}" title="" /> *is* specified.
`[t,P] = solve_riccati_ode(A,B,Q,R,S,PT,tspan)` does the same as the syntax above, but this time the cross-coupling weighting matrix <img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{S}\in\mathbb{R}^{{n}\times{m}}" title="" /> *is* specified.


## Time Vector and Solution Array
Expand Down
Binary file modified Riccati_Differential_Equation.pdf
Binary file not shown.
23 changes: 9 additions & 14 deletions odericcati.m → solve_riccati_ode.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
%==========================================================================
%
% odericcati Solves the Riccati differential equation for the
% solve_riccati_ode Solves the Riccati differential equation for the
% finite-horizon linear quadratic regulator.
%
% [t,P] = odericcati(A,B,Q,R,[],PT,tspan)
% [t,P] = odericcati(A,B,Q,R,S,PT,tspan)
% [t,P] = solve_riccati_ode(A,B,Q,R,[],PT,tspan)
% [t,P] = solve_riccati_ode(A,B,Q,R,S,PT,tspan)
%
% Copyright © 2021 Tamas Kis
% Last Update: 2022-06-07
% Last Update: 2022-08-28
% Website: https://tamaskis.github.io
% Contact: tamas.a.kis@outlook.com
%
% TECHNICAL DOCUMENTATION:
% https://tamaskis.github.io/documentation/Riccati_Differential_Equation.pdf
%
% DEPENDENCIES:
% --> IVP Solver Toolbox (https://www.mathworks.com/matlabcentral/fileexchange/103975-ivp-solver-toolbox)
% IVP Solver Toolbox (https://www.mathworks.com/matlabcentral/fileexchange/103975-ivp-solver-toolbox)
%
%--------------------------------------------------------------------------
%
Expand Down Expand Up @@ -53,13 +53,8 @@
% 4. (A-BR^(-1)S^T,Q-SR^(-1)S^T) detectable
% • if S = 0, this condition reduces to (A,Q^(1/2)) detectable
%
% -----
% NOTE:
% -----
% --> N+1 = length of time vector
%
%==========================================================================
function [t,P] = odericcati(A,B,Q,R,S,PT,tspan)
function [t,P] = solve_riccati_ode(A,B,Q,R,S,PT,tspan)

% ----------------------
% Determines dimensions.
Expand Down Expand Up @@ -91,17 +86,17 @@
dPdt = @(t,P) -(A.'*P+P*A-(P*B+S)/R*(B.'*P+S.')+Q);

% converts matrix-valued ODE to vector-valued ODE
dydt = odefun_mat2vec(dPdt);
dydt = mat2vec_ode(dPdt);

% converts matrix initial condition to vector initial condition
yT = ivpIC_mat2vec(PT);
yT = mat2vec_IC(PT);

% solves Riccati ODE
[t,y] = ode45(dydt,tspan,yT);

% transforms solution matrix for vector-valued ODE into solution array
% for matrix-valued ODE
P = ivpsol_vec2mat(y);
P = vec2mat_sol(y);

% reorders t so that time is increasing
t = flipud(t);
Expand Down

0 comments on commit 6b9c9c6

Please sign in to comment.