简体   繁体   中英

How to use a sinewave function into a state space model as an input (for the B matrix) and get only ONE plot?

I would like to have a sinewave input (as the input force) into my state space model. The main issue is that when I do the step response of the system, I get 10 subplots in ONE plot and I only want to see one plot. I am not sure if I am setting my sine input correctly. I think I might need to do a loop so I don't get multiple plots? Not sure.

Below is my code for a simple Spring-Damping Cart System:

k1=150;
k2=700;
b1=15;
b2=30;
M1=5;
M2=20;
w=1;
t=1e-10:.1:1;
F=sin(w*t); %Sinewave input

A=[0 0 1 0; 0 0 0 1; -k1/M1 k1/M1 -b1/M1 b1/M1; k1/M2 -(k1+k2)/M2 b1/M2 -(b1+b2)/M2];
B=[0 0 1/M1 0]'*F;
C=[1 0 0 0];
D=0;

sys=ss(A,B,C,D); %State Space Model

step(sys)
margin(sys)

希望这只是一个情节

Thank you.

The step function will apply the unit step input, so this line B=[0 0 1/M1 0]'*F; is incorrect. You are modifying the input matrix. In order to see the response of the system due to the step input, you do

k1=150;
k2=700;
b1=15;
b2=30;
M1=5;
M2=20;
w=1;
t=1e-10:.1:1;
%F=sin(w*t); %Sinewave input

A=[0 0 1 0; 0 0 0 1; -k1/M1 k1/M1 -b1/M1 b1/M1; k1/M2 -(k1+k2)/M2 b1/M2 -(b1+b2)/M2];
B=[0 0 1/M1 0]';
C=[1 0 0 0];
D=0;

sys=ss(A,B,C,D); %State Space Model

step(sys)
figure % create a new figure for Bode plot
margin(sys)

The results are

在此处输入图片说明

在此处输入图片说明

In order to define an arbitrary input, you may use lsim . In your case, you can do the following

k1=150;
k2=700;
b1=15;
b2=30;
M1=5;
M2=20;
w=1;
%t=1e-10:.1:1;
t = linspace(0, 100, 1000);
F=sin(w*t); %Sinewave input

A=[0 0 1 0; 0 0 0 1; -k1/M1 k1/M1 -b1/M1 b1/M1; k1/M2 -(k1+k2)/M2 b1/M2 -(b1+b2)/M2];
B=[0 0 1/M1 0]';
C=[1 0 0 0];
D=0;

sys=ss(A,B,C,D); %State Space Model

% step(sys)
% figure
% margin(sys)

output = lsim(sys, F, t);                                
plot(t, output)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM