matlab求解时变系统的Riccati矩阵微分方程

对于代数Riccati方程的求解网上能找到很多的资源,matlab也有成熟的函数,但是对于时变系统的Riccati矩阵微分方程,能找到的资料还比较少。

一、求解代数Riccati方程

可以在网上找到很多资料,如

matlab也有相应的一系列函数 lqr、icare等。

对于这些函数不同的适用范围自己目前了解的还不够,之后补上。

这些函数到底能不能用于求解时变系统自己还没搞清楚。

二、如何处理时变系统

参见matlab官方论坛 Solving Riccati differential equation with time variable matrix

这个帖子给出的方案是ode45中有一个关于处理时变项的例子。

matlab的 ode45 函数官方文档的例子中有一个 ODE with Time-Dependent Terms

内容如下

Consider the following ODE with time-dependent parameters
y ′ ( t ) + f ( t ) y ( t ) = g ( t ) . y'(t) + f(t)y(t) = g(t). y′(t)+f(t)y(t)=g(t).

The initial condition is y 0 = 1 y_0 = 1 y0=1. The function f(t) is defined by the n-by-1 vector f evaluated at times ft. The function g(t) is defined by the m-by-1 vector g evaluated at times gt.

Create the vectors f and g.

matlab 复制代码
ft = linspace(0,5,25);
f = ft.^2 - ft - 3;

gt = linspace(1,6,25);
g = 3*sin(gt-0.25);

Write a function named myode that interpolates f and g to obtain the value of the time-dependent terms at the specified time. Save the function in your current folder to run the rest of the example.

The myode function accepts extra input arguments to evaluate the ODE at each time step, but ode45 only uses the first two input arguments t and y.

matlab 复制代码
function dydt = myode(t,y,ft,f,gt,g)
f = interp1(ft,f,t); % Interpolate the data set (ft,f) at time t
g = interp1(gt,g,t); % Interpolate the data set (gt,g) at time t
dydt = -f.*y + g; % Evaluate ODE at time t

Solve the equation over the time interval [1 5] using ode45. Specify the function using a function handle so that ode45 uses only the first two input arguments of myode. Also, loosen the error thresholds using odeset.

matlab 复制代码
tspan = [1 5];
ic = 1;
opts = odeset('RelTol',1e-2,'AbsTol',1e-4);
[t,y] = ode45(@(t,y) myode(t,y,ft,f,gt,g), tspan, ic, opts);

Plot the solution, |y|, as a function of the time points, |t|.

matlab 复制代码
plot(t,y)

三、如何处理"矩阵"微分方程

在上一节中给出的方法实际上是已经把矩阵微分方程变换成了一列,如果矩阵较大的话还是比较麻烦。

这个帖子给出了较好的解决方案 How can I solve the matrix Riccati differential equation within MATLAB?

或者还可参考
How can I solve a matrix differential equation within MATLAB?

给出的解决方案如下

The matrix Riccati differential equation:

matlab 复制代码
 dX/dt = A'X + XA - XBB'X + Q

can be solved using the functions in the ODE suite.

Assume your dependent matrix "X" is "n"-by-"n", and you have known "n"-by-"n" matrices "A", "B", and "Q". The following method will solve the matrix Riccati differential equation. Save the following as a MATLAB file somewhere on the MATLAB Path.

matlab 复制代码
function dXdt = mRiccati(t, X, A, B, Q)
X = reshape(X, size(A)); %Convert from "n^2"-by-1 to "n"-by-"n"
dXdt = A.'*X + X*A - X*B*B.'*X + Q; %Determine derivative
dXdt = dXdt(:); %Convert from "n"-by-"n" to "n^2"-by-1

Then, you can use the ODE45 function to solve this problem:

matlab 复制代码
[T X] = ode45(@(t,X)mRiccati(t, X, A, B, Q), [0 10], X0) 

For example, using the sample data:

matlab 复制代码
A = [1 1; 2 1]; 
B = [1; 1]; 
Q = [2 1; 1 1];
X0 = [1; 1; 1; 1];

You can use the following command to solve the system of differential equation

matlab 复制代码
[T X] = ode45(@(t,X)mRiccati(t, X, A, B, Q), [0 10], X0) 

ODE45 returns "X" as a vector at each time step. You may use the following code to reshape each row of "X" to get the matrix and store it in a cell array:

matlab 复制代码
[m n] = size(X);
XX = mat2cell(X, ones(m,1), n);
fh_reshape = @(x)reshape(x,size(A));
XX = cellfun(fh_reshape,XX,'UniformOutput',false);

The results of this can be verified by the LQR function:

matlab 复制代码
[K,S,E] = lqr(A, B, Q, 1)

where "S" should have results very similar to the last elements in "X" or "XX". The LQR function computes the steady-state value of the system. In this example, we generated the solution for up to "t = 10", which is an adequate approximation of infinity for this problem.

For more information on ODE45 and other such solvers, refer to the function reference page for ODE45 in the MATLAB documentation.

对于该方法网上还有人追问,如有需要可查阅

四、关于逆向积分

在上面的两个例子中给出的都是初始条件,但实际上Riccati方程给出的往往是终端条件,需要逆向(backward)积分。

对于简单的情况,微分方程中并不含自变量。

此时逆向积分并不复杂,只需要在定义时间区间tspan时把初始时刻和终端时刻调换即可,参考链接为
https://www.mathworks.com/matlabcentral/answers/151336-solving-differential-riccati-equation-with-a-boundary-condition

示例如下

matlab 复制代码
par = [1;2;1];  % q0, q1, and q2
yf = 1;
ti = 0; tf = 2;
opt = odeset('AbsTol',1.0e-07,'RelTol',1.0e-07);
[t,y] = ode45( @riccatiEquation, [tf,ti], yf ,opt, par);

% Visualize
plot(t,y)

function dydx = riccatiEquation(x,y,parameters)
q0 = parameters(1);
q1 = parameters(2);
q2 = parameters(3);

dydx = q0 + q1*y + q2*y*y;
end

或者采用平移的方式,可参考吴受章的最优控制书。

如果实在不行,用变量代换转换成初值问题是不是也行?没有进行仿真验证。

其实对于这类问题有一个更广义的形式,即微分方程的多点边值问题,对此该类问题不能使用ode45解决,而应采用 BVP4CBVP5C 来解决。参考链接如下

五、线性时变系统的Riccati矩阵微分方程

前段时间因事中断了一段时间,现在自己已经不面临这个问题了...

按照前几节的步骤似乎能解决这一问题,但没有经过仿真验证自己心里也不是很有底。

六、补充各类参考链接

时间有限,本来还想给几个例子,看之后自己还有没有机会吧。这里把一些自己在这个过程中的参考链接放上来

How can I solve riccati equation in Simulink with varying state space?

有一些链接给了代码,没来得及细看,但感觉似乎都是时不变系统的

相关推荐
jk_1013 小时前
MATLAB中decomposition函数用法
开发语言·算法·matlab
不想当个技术宅6 小时前
【梯级水电站调度优化】基于自适应权值优化粒子群算法
matlab·粒子群算法·梯级水电站调度优化
蓝色洛特7 小时前
【Matlab元胞自动机】《高速公路人工—自动驾驶混行交通流临界特征研究》
matlab·自动驾驶·元胞自动机·交通仿真
quaer8 小时前
Open-Sora全面开源?
开发语言·算法·机器学习·matlab·矩阵
吱吱鼠叔17 小时前
MATLAB计算与建模常见函数:5.曲线拟合
算法·机器学习·matlab
吱吱鼠叔1 天前
MATLAB数据文件读写:2.矩阵数据读取
数据库·matlab·矩阵
橙意满满的西瓜大侠1 天前
matlab入门学习(二)矩阵、字符串、基本语句、函数
matlab
kuan_li_lyg1 天前
MATLAB - 机械臂手眼标定(眼在手内) - 估计安装在机器人上的移动相机的姿态
开发语言·人工智能·matlab·机器人·ros·机械臂·手眼标定
感谢地心引力1 天前
【MATLAB2024b】安装离线帮助文档(windows)
windows·matlab
通信仿真实验室1 天前
(4)MATLAB生成CRC校验码
开发语言·数据结构·matlab