change state model to transfer function and change from continuous model to discrete model

this is my code
clear; close; clc;
syms a1_head a2_head b hstar
%Parameter Massa
m1 = 8095; % massa train set 1 dalam kg
m2 = 8500; % massa train set 2 dalam kg
g = 10;
c_0_1 = 0.01176;
c_1_1 = 0.00077616;
c_2_1 = 4.48 ;
c_0_2 = 0.01176 ;
c_1_2 = 0.00077616;
c_2_2 = 4.48;
v_0 = 300;
hstar = 120;
a_1 = -1./m1.*(c_1_1 + 2.*c_2_1.*v_0);
a_2 = -1./m2.*(c_1_2 + 2.*c_2_2.*v_0);
a_1_head = 1-(a_1.*hstar);
a_2_head = 1-(a_2.*hstar);
b = 1;
% Model data
A = sym(zeros(4,4));
A(1,2) = a_1_head;
A(3,2) = (a_2_head) - 1;
A(3,4) = a_2_head;
display(A);
B = sym(zeros(4,2));
B(1,1) = -b*hstar;
B(2,1) = b;
B(3,2) = -b*hstar;
B(4,1) = -b;
B(4,2) = b;
display(B);
C = [1 0 0 0;
0 1 0 0;
0 0 1 0;
0 0 0 1];
p_1 = -1./m1.*(c_0_1 - c_2_1.*(v_0).^2);
p_2 = -1./m2.*(c_0_2 - c_2_2.*(v_0).^2);
W = [((a_1 - 1).*v_0) - (p_1.*hstar);
0;
((a_2 - 1).*v_0) - (p_2.*hstar);
((a_1 - 1).*v_0) - (p_1.*hstar);
];
% Q and R matrices for ARE
Q = sym(eye(4)); display(Q);
R = sym(zeros(2,2)); R(1,:) = [1 2]; R(2,:) = [2 3]; display(R);
% Matrix S to find
svar = sym('s',[1 16]);
S = [svar(1:4); svar(5:8); svar(9:12); svar(13:16)];
display(S);
% LHS of ARE: A'*S + S*A' - S*B*Rinv*B'*S
left_ARE = transpose(A)*S + S*A - S*B*inv(R)*transpose(B)*S;
display(left_ARE);
% RHS of ARE: -Q
right_ARE = -Q;
display(right_ARE);
I want to change my model from state space to transfer function
step(tf(ss(A,B(:,1),C,W(:,1))))
i get the error like this
Error using ss (line 274)
The value of the "a" property must be a numeric array without any Inf's or NaN's.
Error in AREtrial3 (line 87)
step(tf(ss(A,B(:,1),C,W(:,1))))
after i get the Transfer function i want convert my model from continuous to discrete because i need find S using idare
I have tried using solve, vpasolve, linsolve but the result is struct with fields
Sol_S =
struct with fields:
s1: [0×1 sym]
s2: [0×1 sym]
s3: [0×1 sym]
s4: [0×1 sym]
s5: [0×1 sym]
s6: [0×1 sym]
s7: [0×1 sym]
s8: [0×1 sym]
s9: [0×1 sym]
s10: [0×1 sym]
s11: [0×1 sym]
s12: [0×1 sym]
s13: [0×1 sym]
s14: [0×1 sym]
s15: [0×1 sym]
s16: [0×1 sym]
an i have try with icare toolbox same
X1 =
[]
K1 =
[]
L1 =
0
0
-0.3134
-1.0087
X is S
K is matriks control
L is eigenvalue closed loop
I need the S matriks to find K matriks for LQR. if the eigenvalue from S matrix is positive i get K matriks. But the problem i have tried many ways still doesn't get the eigenvalue all positif

 Réponse acceptée

A and B are symbolic matrices. You need to convert them to double before passing to ss(). Try following lines of code.
ss_model = ss(double(A),double(B(:,1)),C,W(:,1));
tf_model = tf(ss_model);
step(tf_model)

24 commentaires

you know from the last question error to many output arguments, i can't use the icare toolbox, so i want to use idare toolbox, but in idare is discrete model so i need to change my continuous model to discrete model. After i get the transfer function, how i change my model from continuous to discrete model?
does it use this function?
sysd = c2d(sysc,Ts)
Yes, you can use c2d() to convert the discrete model to continuous mode. However, I think first, you should any analyze your system. It might be the case that solution does not exist. If that is the case, then the conversion from continuous to discrete might not be useful.
ok thank you. Analyse with the contrllable?
I do not know how to analyze this. You need to see the theory behind your system and see if there is a reason that solution does not exist.
ok thank you for help me to answer all my question.
why after i applied this code my B matrix is only 4x1 differen from the B matrix in my model?
ss_model = ss(double(A),double(B(:,1)),C,W(:,1));
The result B is
B =
u1
x1 -11.8
x2 0.1
x3 -0.005
x4 -0.1
Because you are using B(:,1). If you want the complete B matrix, the use double(B).
But when i change to double(B), there is error like this
Error using ss (line 345)
The values of the "b" and "d" properties must be matrices with the same number of columns.
Error in AREtrial2 (line 64)
ss_model = ss(double(A),double(B),C,W(:,1));
Also use W instead of W(:,1).
in here i use w(:,1)
ss_model = ss(double(A),double(B),C,W(:,1));
I meant that you should use W, not W(:,1).
same error
Error using ss (line 345)
The values of the "b" and "d" properties must be matrices with the same number of columns.
Error in AREtrial2 (line 65)
ss_model = ss(double(A),double(B),C,W);
It appears from your code that B and W have the same number of columns (2 columns). Is that correct?
my B is 4x2 matrix and my W is 4x1 matrix
Do you have a D matrix for your system? Or W is working as the D matrix?
i have
dx/dt = Ax(t) + Bu(t) + W(t)
A is 4x4 matrix
B is 4x2 matrix
W is 4x1 matrix
The standard MATLAB functions do not consider this form for the state-space model. ss() consider state-space model in this form
Your model does not follow this form, so you will need to functions. See ode45() to simulate such ODEs.
I assume W is D matrix
I have succeeded use ode45() to simulate my model without control. The purpose i'm using idare function to find S matrix in ARE, after i get the right S matrix (provided that all eigenvalues are valid), i can use to find K matrix. K matrix i use in my my model with lqr control.
my problem is i can't find the right S matrix with all eigenvalues is positiv. If i can't get the right S matrix, i can't get the K matrix for my lqr control. Thank you
is there any function that i can't use it?please help me
I am not sure about this problem. This is not really a MATLAB related problem. Instead, it is a theoretical problem. I don't know how to proceed further.
if i don't want to change to tf first, can i change directly from continuous to discrete?my model is in the form of state space xdot = Ax + Bu?

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by