ss
B = 
C = 2×2
1 0 0 1
D = 2×5
0 0 0 0 0 0 0 0 0 0
Error using ss
The "A" matrix must be a numeric array with no Inf's or NaN's.

1 Kommentar

Torsten
Torsten am 20 Okt. 2022
Give numerical values to the symbolic variables x1 x2 Kv x h.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 20 Okt. 2022

0 Stimmen

The ‘A’ and ‘B’ matrices contain symbolic variables.
Use the subs function to assign numeric values to them, and then the double function to convert those matrices to a numeric array.
I did that here —
%Resolução do exercício 2
syms x1 x2 F1 F2 Kv x h %Variáveis de entrada, estado e saída
syms w1 w2
A=1; %m^3
ro=1000; %kg/m^3
% w1=500; %kg/min
% w2=200; %kg/min
% x1=0.4;
% x2=0.75;
% Kv=(0.7/sqrt(0.5));
% h=0.5;
% x=0.5;
%Cálculo de F1 e F2
% F1=w1/ro;
% F2=w2/ro;
%Equações diferenciais
% syms x1 x2 F1 F2 Kv x h %Variáveis de entrada, estado e saída
dhdt=1/A*(F1+F2-(Kv*(sqrt(h))));
dxdt=(w1/(ro*A*h))*(x1-x)+(w2/(ro*A*h))*(x2-x);
%Matriz A tem dimensão 2x2 (2 variáveis de estado x 2 variáveis de estado)
a11=diff(dhdt,h); %dh com h
a12=diff(dhdt,x); %dh com x
a21=diff(dxdt,h); %dx com h
a22=diff(dxdt,x); %dx com x
%Matriz B tem dimensão 2x5 (2 variáveis de estado x 5 variáveis de entrada)
b11=diff(dhdt,x1); %h com x1
b12=diff(dhdt,x2); %h com x2
b13=diff(dhdt,F1); %h com F1
b14=diff(dhdt,F2); %h com F2
b15=diff(dhdt,Kv); %h com Kv
b21=diff(dxdt,x1); %x com x1
b22=diff(dxdt,x2); %x com x2
b23=diff(dxdt,F1); %x com F1
b24=diff(dxdt,F2); %x com F2
b25=diff(dxdt,Kv); %x com Kv
%Matriz C é 2x2 (2 variáveis de saída x 2 variáveis de saída)
c11=1; %h/dh
c12=0; %h/dx
c21=0; %x/dh
c22=1; %x/dx
%Matriz D é 2x5 (2 variáveis de saída x 5 de entrada)
d11=0;
d12=0;
d13=0;
d14=0;
d15=0;
d21=0;
d22=0;
d23=0;
d24=0;
d25=0;
%Construindo o modelo de espaço de estados
w1=500; %kg/min
w2=200; %kg/min
x1=0.4;
x2=0.75;
Kv=(0.7/sqrt(0.5));
h=0.5;
x=0.5;
A=[a11 a12; a21 a22]
A = 
A = double(subs(A)) % Substitute Values For Variables
A = 2×2
-0.7000 0 0 -1.4000
B=[b11 b12 b13 b14 b15; b21 b22 b23 b24 b25]
B = 
B = double(subs(B)) % Substitute Values For Variables
B = 2×5
0 0 1.0000 1.0000 -0.7071 1.0000 0.4000 0 0 0
C=[c11 c12; c21 c22]
C = 2×2
1 0 0 1
D=[d11 d12 d13 d14 d15; d21 d22 d23 d24 d25]
D = 2×5
0 0 0 0 0 0 0 0 0 0
%Matriz espaço de estados está pronta. Está construída na seguinte ordem
%das variáveis:
%x (estado) = h, x
%u (entrada) = x1, x2, F1, F2, Kv
%y (saída) = h, x
%Ou seja, na matriz B, o termo b23 relaciona x com F1
SYS=ss(A,B,C,D)
SYS = A = x1 x2 x1 -0.7 0 x2 0 -1.4 B = u1 u2 u3 u4 u5 x1 0 0 1 1 -0.7071 x2 1 0.4 0 0 0 C = x1 x2 y1 1 0 y2 0 1 D = u1 u2 u3 u4 u5 y1 0 0 0 0 0 y2 0 0 0 0 0 Continuous-time state-space model.
% The problem is, I get the following error:
% 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 run (line 78)
% SYS=ss(A,B,C,D)
That should now work as desired.
.

4 Kommentare

Torsten
Torsten am 20 Okt. 2022
How do you want to differentiate with respect to F1 and F2 if these are not independent variables ?
Star Strider
Star Strider am 20 Okt. 2022
My pleasure!
The script only needs to know the variables in the two symbolic matrices. For most of the code, ‘F1’ and ‘F2’ are symbolic. It is only necessary to substitute numeric values for the variables in the matrices to get numeric values for the elements of the matrices.
Star Strider
Star Strider am 20 Okt. 2022
I have no idea what the context is.
I got your code to run correctly and give what appears to be an appropriate result. That is the best I can do.
Torsten
Torsten am 20 Okt. 2022
Bearbeitet: Torsten am 20 Okt. 2022
In the question, the professor said the inputs were (x1, x2, F1, F2 e Kv) and outputs were (x, h). He didn't give us the values of F1 and F2, but instead gave the values of w1, w2 and ro.
Then said that wi=ro*Fi.
In this case, you will have to replace
dxdt=(w1/(ro*A*h))*(x1-x)+(w2/(ro*A*h))*(x2-x);
by
dxdt=(F1/(A*h))*(x1-x)+(F2/(A*h))*(x2-x);
This gives two differential equations in x and h:
dhdt=1/A*(F1+F2-(Kv*(sqrt(h))));
dxdt=(F1/(A*h))*(x1-x)+(F2/(A*h))*(x2-x);
Since they are not linear in h and x, they cannot be brought in the state-space form, but must be solved directly by an ODE integrator.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 20 Okt. 2022

Bearbeitet:

am 20 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by