Sine input for a state space model
9 views (last 30 days)
Show older comments
% set up model,in 2nd order form
J = 2; % kg-m^2
k = 2; % N-m/rad, coil spring
J_left = J; J_mid = J; J_right = J;
k_wall = k; k_left = k; k_right = k;
%% set up inertia and elastic matrices
mass = diag([J_left J_mid J_right]);
stif = [(k_wall+k_left) -k_left 0;
-k_left (k_left+k_right) -k_right;
0 -k_right (k_right+k_wall)];
diss = zeros(3,3);
t7=0:1:30;
inp_2nd = [0;5*sin.(sqrt(2*k/J).*t7);0]; %excitation influence matrix
%%convert to state space
%%states: [positions and velocities of (disc_left, disc_mid, disc_rght)]
AA = [zeros(3,3) eye(3); -inv(mass)*stif -inv(mass)*diss];
BB = [zeros(3,1);(mass)\inp_2nd];
p_left = [1 0 0 0 0 0]; %displ of left disc
p_mid = [0 1 0 0 0 0]; %displ of mid disc
p_right= [0 0 1 0 0 0]; %displ of right disc
CC = [p_left;p_mid;p_right];
DD = zeros(3,1);
ini_c = [1 0 -1 0 0 0]
tFinal = 30;
hw3 = ss(AA,BB,CC,DD);
% Plots of each disk
[y,t] = initial(twoa,conditionc,tfinal);
subplot(3,1,1)
plot(t,y(:,1))
title('response to initial conditions c')
ylabel('Left (radians)')
subplot(3,1,2)
plot(t,y(:,2))
xlim([0 10])
ylabel('Mid (radians)')
subplot(3,1,3)
plot(t,y(:,3))
xlim([0 10])
ylabel('Right (radians)')
xlabel('time (seconds)')


So I'm not sure how to use a sinusoidal input for my B matrix to plot a response is there anyway I can get some help in general on how to put a sine input into a state space model represantation for plotting purposes.
0 Comments
Answers (1)
Sulaymon Eshkabilov
on 1 Aug 2019
Hi,
There are several errors in your script:
(1) inp_2nd = [0;5*sin.(sqrt(2*k/J).*t7);0]; has to be inp_2nd = [0, 5*sin(sqrt(2*k/J)*t7), 0];
(2) BB = [zeros(3,1);(mass)\inp_2nd]; does not work because the size of the mass matrix is 3-by-3 and the size of inp_2nd is 33.
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!