Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solving Matrix Riccati

Subject: Solving Matrix Riccati

From: Jeremy

Date: 5 Apr, 2013 23:20:12

Message: 1 of 4

I'm new to MATLAB and trying to use ODE45 to find the coefficients of the matrix Riccati equation for a controls problem.

I'm not sure what I'm doing wrong.

I've defined my Riccati equation in a function 'regulator'

%Define matrices
function dS=regulator(t,S)

A=[0 1;0 -2.972];
B=[0;390];
Q=[(1/(pi^2)) 0;0 30];
R=1;

dS=-1*(A'*S+S*A-S*B*(R^-1)*B'*S+Q);

end

Then I'm just going straight to ODE45, doing something like this:

[t,S]=ode45('regulator',[0 5],[0 0;0 0])

looking for a solution to matrix S.

Can I solve like this or do I have to multiply out all the terms of S? Assuming S is

S = [s11(t) s12(t) ; s12(t) s22(t)];

Any help would be appreciated.

Subject: Solving Matrix Riccati

From: Nasser M. Abbasi

Date: 5 Apr, 2013 23:41:57

Message: 2 of 4

On 4/5/2013 6:20 PM, Jeremy wrote:
> I'm new to MATLAB and trying to use ODE45 to find the coefficients of the matrix
>Riccati equation for a controls problem.

Any reason why are you not using the specalized funtions for Riccati solver
in the control systems toolbox?

http://www.mathworks.com/help/control/ref/care.html

"care

Continuous-time algebraic Riccati equation solution"


>
> I'm not sure what I'm doing wrong.
>
> I've defined my Riccati equation in a function 'regulator'
>
> %Define matrices
> function dS=regulator(t,S)
>
> A=[0 1;0 -2.972];
> B=[0;390];
> Q=[(1/(pi^2)) 0;0 30];
> R=1;
>
> dS=-1*(A'*S+S*A-S*B*(R^-1)*B'*S+Q);
>
> end
>
> Then I'm just going straight to ODE45, doing something like this:
>
> [t,S]=ode45('regulator',[0 5],[0 0;0 0])
>
> looking for a solution to matrix S.
>
> Can I solve like this or do I have to multiply out all the terms of S? Assuming S is
>
> S = [s11(t) s12(t) ; s12(t) s22(t)];
>
> Any help would be appreciated.
>

Subject: Solving Matrix Riccati

From: Jeremy

Date: 6 Apr, 2013 14:16:10

Message: 3 of 4

I can't use the algebraic Riccati eqn for this problem. It looks like 'care' is only used to solve problems where the ARE is used.


"Nasser M. Abbasi" wrote in message <kjnng5$aao$1@speranza.aioe.org>...
> On 4/5/2013 6:20 PM, Jeremy wrote:
> > I'm new to MATLAB and trying to use ODE45 to find the coefficients of the matrix
> >Riccati equation for a controls problem.
>
> Any reason why are you not using the specalized funtions for Riccati solver
> in the control systems toolbox?
>
> http://www.mathworks.com/help/control/ref/care.html
>
> "care
>
> Continuous-time algebraic Riccati equation solution"
>
>
> >
> > I'm not sure what I'm doing wrong.
> >
> > I've defined my Riccati equation in a function 'regulator'
> >
> > %Define matrices
> > function dS=regulator(t,S)
> >
> > A=[0 1;0 -2.972];
> > B=[0;390];
> > Q=[(1/(pi^2)) 0;0 30];
> > R=1;
> >
> > dS=-1*(A'*S+S*A-S*B*(R^-1)*B'*S+Q);
> >
> > end
> >
> > Then I'm just going straight to ODE45, doing something like this:
> >
> > [t,S]=ode45('regulator',[0 5],[0 0;0 0])
> >
> > looking for a solution to matrix S.
> >
> > Can I solve like this or do I have to multiply out all the terms of S? Assuming S is
> >
> > S = [s11(t) s12(t) ; s12(t) s22(t)];
> >
> > Any help would be appreciated.
> >

Subject: Solving Matrix Riccati

From: Bart

Date: 6 Apr, 2013 16:51:08

Message: 4 of 4

"Jeremy" wrote in message <kjnm7c$282$1@newscl01ah.mathworks.com>...
> I'm new to MATLAB and trying to use ODE45 to find the coefficients of the matrix Riccati equation for a controls problem.
>
> I'm not sure what I'm doing wrong.
>
> I've defined my Riccati equation in a function 'regulator'
>
> %Define matrices
> function dS=regulator(t,S)
>
> A=[0 1;0 -2.972];
> B=[0;390];
> Q=[(1/(pi^2)) 0;0 30];
> R=1;
>
> dS=-1*(A'*S+S*A-S*B*(R^-1)*B'*S+Q);
>
> end
>
> Then I'm just going straight to ODE45, doing something like this:
>
> [t,S]=ode45('regulator',[0 5],[0 0;0 0])
>
> looking for a solution to matrix S.
>
> Can I solve like this or do I have to multiply out all the terms of S? Assuming S is
>
> S = [s11(t) s12(t) ; s12(t) s22(t)];
>
> Any help would be appreciated.

Jeremy: as far as I know, the ODE function only accepts vectors as input. So you will have to reshape your matrix S into a vector.

This should work:
function [dP] = fun_ric(t,Pin)
%fun_ric

% reshape input
P = reshape(Pin,2,2);

% system matrices
A=[0 1;0 -2.972];
B=[0;390];
Q=[(1/(pi^2)) 0;0 30];
R=1;
Ri = R^-1;

% Ricatti equation:
dPt = A'*P+P*A+Q-P*B*Ri*B'*P;

% reshape
dP = reshape(dPt,4,1);
end

%% Test ricatti
clear all, close all, clc

%% ode params
P0 = zeros(2);
tspan = [0 2];

%% simulate
[t, P] = ode45('fun_ric',tspan,P0);

% P matrix (comparable with: P=care(A,B,Q,R))
Ptot = reshape(P(end,:),2,2)

figure(1)
plot(t,P)


If you compare the outcome of 'care' it will be the same as for Ptot when you simulate long enough (100 sec).

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us