码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • matlab求解时变系统的Riccati矩阵微分方程


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

    一、求解代数Riccati方程

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

    • https://blog.csdn.net/m0_62299908/article/details/127807014

    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.

    ft = linspace(0,5,25);
    f = ft.^2 - ft - 3;
    
    gt = linspace(1,6,25);
    g = 3*sin(gt-0.25);
    
    • 1
    • 2
    • 3
    • 4
    • 5

    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.

    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
    
    • 1
    • 2
    • 3
    • 4

    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.

    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);
    
    • 1
    • 2
    • 3
    • 4

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

    plot(t,y)
    
    • 1

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

    在上一节中给出的方法实际上是已经把矩阵微分方程变换成了一列,如果矩阵较大的话还是比较麻烦。
    这个帖子给出了较好的解决方案 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:

     dX/dt = A'X + XA - XBB'X + Q
    
    • 1

    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.

    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
    
    • 1
    • 2
    • 3
    • 4

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

    [T X] = ode45(@(t,X)mRiccati(t, X, A, B, Q), [0 10], X0) 
    
    • 1

    For example, using the sample data:

    A = [1 1; 2 1]; 
    B = [1; 1]; 
    Q = [2 1; 1 1];
    X0 = [1; 1; 1; 1];
    
    • 1
    • 2
    • 3
    • 4

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

    [T X] = ode45(@(t,X)mRiccati(t, X, A, B, Q), [0 10], X0) 
    
    • 1

    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:

    [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);
    
    • 1
    • 2
    • 3
    • 4

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

    [K,S,E] = lqr(A, B, Q, 1)
    
    • 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.

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

    • https://www.mathworks.com/matlabcentral/answers/225984-how-can-i-solve-matrix-riccati-differential-equation
    • how can i solve matrix riccati differential equation?

    四、关于逆向积分

    在上面的两个例子中给出的都是初始条件,但实际上Riccati方程给出的往往是终端条件,需要逆向(backward)积分。
    对于简单的情况,微分方程中并不含自变量。
    此时逆向积分并不复杂,只需要在定义时间区间tspan时把初始时刻和终端时刻调换即可,参考链接为
    https://www.mathworks.com/matlabcentral/answers/151336-solving-differential-riccati-equation-with-a-boundary-condition

    示例如下

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    或者采用平移的方式,可参考吴受章的最优控制书。
    如果实在不行,用变量代换转换成初值问题是不是也行?没有进行仿真验证。

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

    • Using ode45 to solve system of ODEs with some initial conditions and some terminal conditions
    • Solve BVP with Multiple Boundary Conditions
    • https://stackoverflow.com/questions/29162100/how-can-i-solve-a-system-of-odes-with-some-terminal-conditions-in-matlab

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

    前段时间因事中断了一段时间,现在自己已经不面临这个问题了…
    按照前几节的步骤似乎能解决这一问题,但没有经过仿真验证自己心里也不是很有底。

    六、补充各类参考链接

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

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

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

    • 这个代码声称解决的是时变矩阵微分方程,但得到的是近似解。而且还有论文支撑,看上去最靠谱 Recursive Approximate Solution to Matrix Diff. Riccati Eq.
    • Solve Riccati Differential Equation (solve_riccati_ode)
    • symmetric differential matrix Riccati equations
    • 这份代码和上一份是同一个人上传到MathWorks网站上的,相差仅一天,可能是一样的 The solve the matrix Riccati differential equation
    • Algebraic Riccati Equation Solver
    • 这份代码也有论文,但似乎很专业,可能是数学专业的 Invariant Galerkin Ansatz Spaces and Davison-Maki Methods for the Numerical Solution of Differential Riccati Equations
  • 相关阅读:
    第五十五章 使用 NSD (Windows) - 在备用 TCP 端口上启动 NSD
    转换罗马数字
    抖音招聘直播报白:短视频流量红利和精准推送,让招聘更精准
    养了个羊(简易版)
    聊天室(二)__ unipush 推送实现详细教程
    HTML静态网页成品作业(HTML+CSS)——非遗昆曲介绍设计制作(1个页面)
    Plooks大型视频在线一起看网站源码
    基于Quartz实现动态定时任务
    这就是艺术,优雅的二维码生成器「GitHub 热点速览」
    警用移动执法远程视频监控方案:安防视频监控系统EasyCVR+4G/5G移动执法仪
  • 原文地址:https://blog.csdn.net/gsgbgxp/article/details/133647223
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号