How to do solve Riccati differential equation backward
Show older comments
I am having problem. I want to solve Riccati differential equation backward for time varying system. I try to follow the examples, and I wrote a code, but the result was strange and I have no idea about it, please help me.
close all; clear all; clc
Tspan = 1.7:-0.001:0;
v = openfig('acc.fig') ;
H = findobj(v,'type','line');
nn = get (H, 'ydata');
mm = get(H, 'xdata');
q = openfig('angle.fig') ;
Q = findobj(q,'type','line');
qq = get (Q, 'ydata');
vv = get(Q, 'xdata');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% this is to find final condition
I = 0.0200;
L = 0.325;
g = 9.81;
m = 0.9847;
C = 0.0076;
Ibar = I + m*L*L;
AA=[0 0 1 0; 0 0 0 1;0 0 0 0; 0 m*g*L/Ibar 0 -C/Ibar]; %%at the final condition, angle=0;
BB = [0 0 1 -m*L/Ibar];
BB = BB';
Z = [0.0002 0 0 0; 0 0 0 0;0 0 0.0005 0; 0 0 0 0]; %%Z is Q and RR is R
N = zeros(4,1);
RR = 0.002;
[K,S,e] = LQR(AA,BB,Z,RR,N) ; %%S is the final condition, Backward integration use final condition
[T P] = ode45(@(t,p) MM_mRiccati22(t,p,mm,nn,qq,vv), Tspan,S );
plot(T,P)
title('NUMERIC RICCATI-MATRIX SOLUTION');
xlabel('time t');
ylabel('solution y');
%%Calculate K
[m n] = size(P);
PP = mat2cell(P, ones(m,1), n);
fh_reshape = @(x)reshape(x,size(Z));
PP = cellfun(fh_reshape,PP,'UniformOutput',false);
num_t = length(Tspan);
K1=zeros(1,1701);
K2=zeros(1,1701);
K3=zeros(1,1701);
K4=zeros(1,1701);
for i=1:num_t
PPP = cell2mat(PP(i)); %---- P(t)
angle = spline(vv,qq,Tspan(i));
angle=angle*180/pi;
b41 = -m*L*cos(angle)/Ibar;
b = [0; 0; 1; b41]; %---- b(t)
KK = -inv(RR)*b'*PPP;
K1(i) = KK(1);
K2(i) = KK(2);
K3(i) = KK(3);
K4(i) = KK(4);
end
figure(2)
plot(Tspan,K1,'k', Tspan,K2, 'r', Tspan,K3, 'g', Tspan,K4,'b')
hleg = legend('K1','K2','K3','K4');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% the Riccati function
I = 0.0200;
L = 0.325;
g = 9.81;
m = 0.9847;
C = 0.0076;
Ibar = I + m*L*L;
Q=[0.0002 0 0 0; 0 0 0 0;0 0 0.0005 0; 0 0 0 0];
R=0.002;
angle = spline(vv,qq,t);
angle=angle*180/pi;
acc = spline(mm,nn,t);
a42 = (m*g*L*cos(angle) + m*L*sin(angle)*acc)/Ibar;
a44 = -C/Ibar;
b41 = -m*L*cos(angle)/Ibar;
A = [0 0 1 0; 0 0 0 1; 0 0 0 0; 0 a42 0 a44];
b = [0; 0; 1; b41];
p = reshape(p, size(A)); %Convert from "n^2"-by-1 to "n"-by-"n"
dpdt = p*b*(R^-1)*b'*p -p*A -A'*p -Q; %Determine derivative
dpdt = dpdt(:); %converting dxdt into a column vector as expected by ode45
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end
1 Comment
upinderjeet
on 16 Mar 2014
did u find the answer...i am also trying to find the way to solve the riccati equation backward in time..if you have found the way please share it with me
Answers (0)
Categories
Find more on Matrix Computations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!