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

조회 수: 1 (최근 30일)
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.

채택된 답변

Star Strider
Star Strider 2022년 5월 5일
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
Paul
Paul 2022년 5월 5일
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));

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paul
Paul 2022년 5월 4일
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.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by