我正在尝试在 MATLAB 中执行闭环系统,它使用以下 ode:
function [dy] = ode_pend(t,y)
dy = zeros(6,1);
m0=1;m1=0.5;m2=0.5;l1=1;l2=1;g=9.81;
d0=m0+m1+m2;
d1=m1*(l1/2)^2+m2*l1^2+(m1*(l1/2)^2)/3;
d2=m2*(l2/2)^2+(m2*(l2/2)^2)/3;
d3=m2*l1*l2/2;
f1=(m1*l1/2+m2*l1)*g;
f2=m2*l2/2*g;
%calling the input function
[u,V1]=ip(y);
%defining new variables for simplicity
A1=d1-(d3^2/d2)*(cos(y(2)-y(3)))^2;
A2=(f1/g)*cos(y(2))-((f2*d3)/(g*d2))*cos(y(3))*cos(y(2)-y(3));
A3=d0*A1-(f2^2*A1/(g^2*d2))*(cos(y(3)))^2-(A2*f1/g)*cos(y(2))+
(A2*f2*d3/(g*d2))*cos(y(3))*cos(y(2)-y(3));
%ode
dy(1)=y(4);
dy(2)=y(5);
dy(3)=y(6);
dy(4)=(u*A1+(A2*d3^2/d2)*sin(y(2)-y(3))*cos(y(2)-y(3))*(y(5))^2+
(A2*f2*d3/d2)*sin(y(3))*cos(y(2)-y(3))+A2*d3*sin(y(2)-y(3))*(y(6))^2-
A2*f1*sin(y(2))-(A1*(f2)^2/(g*d2))*sin(y(3))*cos(y(3))+(f1*A1/g)*sin(y(2))*
(y(5))^2+(A1*f2/g)*sin(y(3))*(y(6))^2-(f2*A1*d3/(g*d2))*cos(y(3))*sin(y(2)-
y(3))*(y(5))^2)/A3;
dy(5)=(((f2*d3/(g*d2))*cos(y(3))*cos(y(2)-y(3))-(f1/g)*cos(y(2)))*dy(4)-
(d3^2/d2)*sin(y(2)-y(3))*cos(y(2)-y(3))*(y(5))^2-
(f2*d3/d2)*sin(y(3))*cos(y(2)-y(3))-d3*sin(y(2)-
y(3))*y(6)^2+f1*sin(y(2)))/A1;
dy(6)=(-(f2/g)*cos(y(3))*dy(4)-d3*cos(y(2)-y(3))*dy(5)+d3*sin(y(2)-y(3))*
(y(5))^2+f2*sin(y(3)))/d2;
end
我正在调用另一个函数[u,V1]=ip(y)
来计算每个时间步的输入和我的 Lyapunov 函数。我需要绘制输入和 Lyapunov 函数的时间响应以供进一步使用,那么有什么方法可以从我的 ode 中提取u
和V1
向量?
要运行 ode 我正在调用以下脚本
a=0;
b=12;
fs=10000;
tspan=a:(1/fs):b;
x = [1;(deg2rad(90));deg2rad(180);0;0; 0.1];
[t,y]= ode45(@ode_pend,tspan,x);