How do I keep f as a variable in a state space model, as f is supposed to be the input variable??

1 vue (au cours des 30 derniers jours)
m1=1;
m2=1;
l1=1;
l2=1;
M=5;
g=10;
A_motor=[0,1,0,0,0,0;0,0,(-m1*g)/M,0,(-m2*g/M),0;0,0,0,1,0,0;0,0,(g/l1)-(-m2*g)/(M*l1),0,(-m2*g)/(M*l2),0;0,0,0,0,0,1;0,0,(-m1*g)/(M*l2),0,(g/l2)-(m2*g)/(M*l2),0];
B_motor=[0;f/M;0;-f/(M*l1);0;-f/(M*l2)];
C_motor=[0,1,0,1,0,1];
D_motor=[0];
When I input this as my code I recieve an error stating that f is not defined, however I need to keep f as the input variable.

Réponse acceptée

Star Strider
Star Strider le 5 Mai 2022
Since ‘f’ is only defined in ‘B_motor’ simply create an anonymous function from it, and then from ‘motor_ss’ (to keep with the existing names).
m1=1;
m2=1;
l1=1;
l2=1;
M=5;
g=10;
A_motor=[0,1,0,0,0,0;0,0,(-m1*g)/M,0,(-m2*g/M),0;0,0,0,1,0,0;0,0,(g/l1)-(-m2*g)/(M*l1),0,(-m2*g)/(M*l2),0;0,0,0,0,0,1;0,0,(-m1*g)/(M*l2),0,(g/l2)-(m2*g)/(M*l2),0];
B_motor= @(f) [0;f/M;0;-f/(M*l1);0;-f/(M*l2)];
C_motor=[0,1,0,1,0,1];
D_motor=[0];
motor_ss = @(f) ss(A_motor, B_motor(f), C_motor, D_motor)
motor_ss = function_handle with value:
@(f)ss(A_motor,B_motor(f),C_motor,D_motor)
figure
step(motor_ss(0.0000001))
figure
step(motor_ss(0.0001))
I considered Create State-Space Model with Both Fixed and Tunable Parameters, however that has the tunable parameters only in the ‘A’ matrix (appropriately), so that would not appear to apply here.
See the documentation section on Anonymous Functions if you are not familiar with them.
.
  1 commentaire
Paul
Paul le 5 Mai 2022
Hi Star,
Tunable parameters work fine anywhere in the model
m1=1;
m2=1;
l1=1;
l2=1;
M=5;
g=10;
f = realp('f',0); % default value of 0
A_motor=[0,1,0,0,0,0;0,0,(-m1*g)/M,0,(-m2*g/M),0;0,0,0,1,0,0;0,0,(g/l1)-(-m2*g)/(M*l1),0,(-m2*g)/(M*l2),0;0,0,0,0,0,1;0,0,(-m1*g)/(M*l2),0,(g/l2)-(m2*g)/(M*l2),0];
B_motor=[0;f/M;0;-f/(M*l1);0;-f/(M*l2)];
C_motor=[0,1,0,1,0,1];
D_motor=[0];
sys = ss(A_motor,B_motor,C_motor,D_motor)
sys = Generalized continuous-time state-space model with 1 outputs, 1 inputs, 6 states, and the following blocks: f: Scalar parameter, 3 occurrences. Type "ss(sys)" to see the current value, "get(sys)" to see all properties, and "sys.Blocks" to interact with the blocks.
step(sampleBlock(sys,'f',0.0001));

Connectez-vous pour commenter.

Plus de réponses (1)

Paul
Paul le 4 Mai 2022
Hello Arya,
Assuming that f(t) is the input to the system, it is not included in the B-matrix. Rathe, the B-matrix should be:
B_motor=[0;1/M;0;-1/(M*l1);0;-1/(M*l2)];
and the state space model of the system is:
xdot = A_motor * x + B_motor * f
y = C_motor * x + D_motor * f
If f(t) is not the input to the system, further clarification is needed on what f actually is.

Catégories

En savoir plus sur MATLAB 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!

Translated by