将 equationsToMatrix 与函数(因变量)一起使用

Using equationsToMatrix with functions (dependent variables)

我正在尝试使用 equationsToMatrix 函数查找状态 space 倒立(一件)摆的模型。我正在使用以下代码:

%Declaration of Variables
syms x(t) t M m ddx(t) l th(t) ddth(t) dth(t) b1 b2 dx(t) F(t) I

%Nonlinear Equations
eqn1=eq((I+m*l^2)*ddth+m*l*cos(th)*ddx-m*g*l*sin(th)+b2*dth,0)
eqn2=eq((M+m)*ddx+m*l*cos(th)*ddth-m*l*sin(th)*(dth)^2+b1*dx,F)

%Linear Equations
eqn1L=subs (eqn1,[cos(th),sin(th(t)),dth(t)^2],[1,th(t),0])
eqn2L=subs (eqn2,[cos(th),sin(th(t)),dth(t)^2],[1,th(t),0])

%Finding State Space Model
[A,B]=equationsToMatrix([eqn2L,eqn1L],[x(t),dx(t),th(t),dth(t)])
C=[1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1];
D=[0;0;0;0];

sys = ss(A,B,C,D)

MATLAB 抛出以下错误:

Error using sym.getEqnsVars>checkVariables (line 92)
The second argument must be a vector of symbolic variables.

Error in sym.getEqnsVars (line 54)
checkVariables(vars);

Error in sym/equationsToMatrix (line 55)
[eqns,vars] = sym.getEqnsVars(argv{:});

Error in Linearization_Test (line 10)
[A,B]=equationsToMatrix([eqn2L,eqn1L],[x(t),dx(t),th(t),dth(t)])

如何解决这个错误?

您应该用没有时间依赖性的变量替换变量:

syms x_ dx_ th_ dth_
X = [x(t),dx(t),th(t),dth(t)];
X_ = [x_,dx_,th_,dth_];
[A,B]=equationsToMatrix(subs([eqn2L,eqn1L], X, X_),X_)