4 Dof response with state space formulation and ode45

2 Ansichten (letzte 30 Tage)
Orhun KALYONCU
Orhun KALYONCU am 6 Mai 2022
%I am new learner in Matlab. So it can be hard to write a code when the structural system is complicating. I have a project for four story building that parameters of each story is the same (k=5000 N/m, and m = 4000 kg). I want to get a response of this building for each story but the ode function always gets an error due to the inconsistent of data. Actually, I can't recognize where I made mistake. I write this code below that the code is written in terms of state space formulation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function v=elcentrofunc(t, elCentro)
fixed = fix(t/0.02)+1;
v = elCentro(fixed);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tempElCentro = readmatrix("ElCentroAccelerations.txt");
elCentro=zeros(1,1560);
for i=1:1:1560
elCentro(i)=tempElCentro(i,1)*9.81;
end
M = [4000 0 0 0; 0 4000 0 0; 0 0 40000 0; 0 0 0 4000];
K = [10000 -5000 0 0; -5000 10000 -5000 0; 0 -5000 10000 -5000; 0 0 -5000 5000];
n = 4; % 4 DOF system
B = [4000 ; 4000 ; 4000 ; 4000]; %force affects according to the massess of each story
A1 = [zeros(n) eye(n); -inv(M)*K zeros(n)]; %Neglect Damping
f = inv(M)*B ;
yinitial = [0; 0; 0; 0];
tspan= linspace(0,31.18,1560);
odefun = @(t,y) [A1*y+[0;0; f]*elcentrofunc(t, elCentro)];
[t,y] = ode45(odefun, tspan, yinitial);
p=plot(t,y(:,1),t,y(:,2));
xlim([0 30])
p(1).LineWidth = 1;
p(2).LineWidth = 1;
p(3).LineWidth = 1;
p(4).LineWidth = 1;
Error is like;
Error using *
Incorrect dimensions for matrix multiplication. Check that the
number of columns in the first matrix matches the number of rows
in the second matrix. To perform elementwise multiplication, use
'.*'.
Error in @(t,y)[A1*y+[0;0;f]*elcentrofunc(t,elCentro)]
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 106)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
The forced data is El Centro Earthquake Excitation. Thank you so much!

Antworten (1)

Jon
Jon am 6 Mai 2022
Bearbeitet: Jon am 6 Mai 2022
You may have other errors too, but one thing that doesn't look correct is the multiplication
A1*y
in your odefun. A1 is an 8x8 matrix, y is a 4x1 vector (at least yinitial, the initial y is), So either A1 should have 4 columns, or yinitial should have 8 rows (a length 8 vector).
  6 Kommentare
Jon
Jon am 6 Mai 2022
I'm not familiar with the details of the physics and governing equations that you are trying to simulate to know if your state vector, y should really have 4 elements, in which case you need to check your equations for A1 and determine why it is not 4 x 4, or vice verse, determine that A1 is really 8x8, in which case you should set
yinitial = [0;0;0;0;0;0;0;0] % 8 element initial condition vector
or equivalently, and clearer
yinital = zeros(8,1)
The second term in your odefun also does not look correct. You have the term
[0;0; f]*elcentrofunc(t, elCentro)
and
f = inv(M)*B ;
so f will be 4x1 and [0;0;f] will be 6x1. Assuming elcentrofunc(t,eleCentro) gives a scalar (1x1) then this second term will be 6x1 which is not compatible with either the first term having 8 rows or 4 rows.
So I would suggest reviewing the physical equations, and getting clear on what the appropriate dimensions are, and then tracing through what if any coding errors you have.
Orhun KALYONCU
Orhun KALYONCU am 6 Mai 2022
Thank you! I got it right now. It works. My pleasure!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by