📄 tdof_ss_time_ode45_slnk.m
字号:
echo off
% tdof_ss_time_ode45_slnk.m state-space solution of tdof model with
% initial conditions, step function forcing function and displacement
% outputs using the ode45 solver or Simulink, user is prompted for
% damping values.
% Solves for time domain response of tdof problem using Matlab's
% ODE45 solver, a Runga-Kutta method of solving differential equations,
% and also using Matlab's Simulink block-diagram simulation tool.
clear all;
global a b u % this is required to have the parameters available
% for the function
which_run = input('enter "1" for Simulink or "enter" for ode45 run ... ');
if isempty(which_run)
which_run = 0
end
% define the values of masses, springs, dampers and Forces
m1 = 1;
m2 = 1;
m3 = 1;
c1 = input('input value for c1, default 0.0, ... ');
if (isempty(c1))
c1 = 0.0;
else
end
c2 = input('input value for c2, default 0.0, ... ');
if (isempty(c2))
c2 = 0.0;
else
end
k1 = 1;
k2 = 1;
F1 = 1;
F2 = 0;
F3 = -2;
% define the system matrix, a
a = [ 0 1 0 0 0 0
-k1/m1 -c1/m1 k1/m1 c1/m1 0 0
0 0 0 1 0 0
k1/m2 c1/m2 -(k1+k2)/m2 -(c1+c2)/m2 k2/m2 c2/m2
0 0 0 0 0 1
0 0 k2/m3 c2/m3 -k2/m3 -c2/m3];
% define the input matrix, b
b = [ 0
F1/m1
0
F2/m2
0
F3/m3];
% define the output matrix for transient response, c, displacements only
c = [1 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 1 0];
% define the direct transmission matrix for transient response, d, the same number of rows as c and
% the same number of columns as b
d = zeros(3,1);
if which_run == 0 % transient response using the ode45 command
u = 1;
ttotal = input('Input total time for Simulation, default = 10 sec, ... ');
if (isempty(ttotal))
ttotal = 10;
else
end
tspan = [0 ttotal];
x0 = [0 -1 -1 2 1 -2]'; % initial condition vector, note transpose
options = []; % no options specified for ode45 command
[t,x] = ode45('tdofssfun',tspan,x0,options);
y = c*x'; % note transpose, x is calculated as a column vector in time
plot(t,y(1,:),'k+-',t,y(2,:),'kx-',t,y(3,:),'k-')
title('State-Space Displacements of dof 1, 2 and 3')
xlabel('Time, sec')
ylabel('Vibration Displacements')
legend('dof 1','dof 2','dof 3')
grid
else % setup Simulink run
% define the direct transmission matrix for transient response, d, the same number of rows as c and
% the same number of columns as b
% define time for simulink model
ttotal = input('Input total time for Simulation, default = 10 sec, ... ');
if (isempty(ttotal))
ttotal = 10;
else
end
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp('Run the Simulink model "tdof_ss_simulink.mdl" and then');
disp('run the plotting file "tdof_ss_time_slnk_plot.m"');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -