Using 'solve' function with variables:
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello I'm using the following code to get a state space model, but having a trouble using 'solve' function.
------------------
%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
syms x_ dx_ ddx_ th_ dth_ ddth_
X = [x(t),dx(t),ddx(t),th(t),dth(t)];
X_ = [x_,dx_,th_,ddx_,dth_];
eqndx_=eq(dx_,dx_)
ddx_solution=solve(subs(eqn2L,X,X_),ddx_)
eqndth_=eq(dth_,dth_)
ddth_solution=solve(subs(eqn1L,X,X_),ddth_)
eqns_=[eqndx_,ddx_solution,eqndth_,ddth_solution];
[A,B]=equationsToMatrix(eqns_,[x_,dx_,th_,dth_])
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)
------------------
and this is the output for lines 13..22(end)
|eqndx_ =
dx_ == dx_
ddx_solution =
Empty sym: 0-by-1
eqndth_ =
dth_ == dth_
ddth_solution =
Empty sym: 0-by-1
A =
[ 0, 0, 0, 0]
[ 0, 0, 0, 0]
[ 0, 0, 0, 0]
[ 0, 0, 0, 0]
B =
0
0
0
0
Error using ss (line 260)
The value of the "a" property must be a numeric array without any Inf's or NaN's.
Error in Linearization_Test (line 22)
sys = ss(A,B,C,D)|
0 commentaires
Réponses (1)
Nicolas Schmit
le 11 Sep 2017
Replace
X = [x(t),dx(t),ddx(t),th(t),dth(t)];
X_ = [x_,dx_,th_,ddx_,dth_];
with
X = [x(t),dx(t),ddx(t),th(t),dth(t), ddth(t)];
X_ = [x_, dx_,ddx_,th_, dth_, ddth_];
Note that ss() does not work on symbolic variables.
0 commentaires
Voir également
Catégories
En savoir plus sur Equation Solving dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!