Azzera filtri
Azzera filtri

'MY_ODE_WITHOUT_TLD returns a vector of length 2688, but the length of initial conditions vector is 2' why this error is showing?

2 visualizzazioni (ultimi 30 giorni)
function dydt = my_ode_without_tld(i,y)
% tspan = i; %% Time span
%% Initial inputs
m1 = 10; %% mass of the structure(kg)
k1 = 15; %% stiffness of the structure(N/m)
c1 = 5; %% damping of the structure(Ns/m)
A = 0.05; %% Amplitude of ground displacement(m)
f = 1; %% Input frequencycy(Hz)
fs = 1.111; %% Frequency of structure(Hz)
n = 1; %% Tuning ratio
%% define frequency
w1 = 3.48; %% frequency of structure
%% define damping ratio of structure
r1 = 0.01; %c1/(2*m1*w1);
%% define ground acceleration
ugdd = load('timehistory_elcentro.DAT')';
%% Equation to solve
dydt = [y(2) -ugdd-(2*r1*w1*y(2))-((w1)^2*y(1))].';
%% To run mass spring damper system
i = load('timedata_elcentro.dat')';
y = [0 0];
%% Solve using ode45
[tsol,ysol] = ode45('my_ode_without_tld', i, y, [1 0;0 1]);
%% plotting
plot(tsol,ysol(:,1))
xlabel('time(sec)')
ylabel('displacement(m)')
grid on
title('Displacement response of structure')
figure
plot(tsol,ysol(:,2))
xlabel('time(sec)')
ylabel('velocity(m/s)')
grid on
title('Velocity response of structure')

Risposte (1)

Torsten
Torsten il 9 Mar 2022
The array dydt has 2688 elements (most probably because the vector ugdd has 2687 elements).
The ode solver expects dydt of length 2.
Try
function main
%% To run mass spring damper system
i = load('timedata_elcentro.dat')';
ugdd = load('timehistory_elcentro.DAT')';
y = [0 0];
%% Solve using ode45
[tsol,ysol] = ode45(@(t,y)my_ode_without_tld(t,y,i,ugdd), [i(1),i(end)], y);
%% plotting
plot(tsol,ysol(:,1))
xlabel('time(sec)')
ylabel('displacement(m)')
grid on
title('Displacement response of structure')
figure
plot(tsol,ysol(:,2))
xlabel('time(sec)')
ylabel('velocity(m/s)')
grid on
title('Velocity response of structure')
end
function dydt = my_ode_without_tld(t,y,tdata,ydata)
%% Initial inputs
m1 = 10; %% mass of the structure(kg)
k1 = 15; %% stiffness of the structure(N/m)
c1 = 5; %% damping of the structure(Ns/m)
A = 0.05; %% Amplitude of ground displacement(m)
f = 1; %% Input frequencycy(Hz)
fs = 1.111; %% Frequency of structure(Hz)
n = 1; %% Tuning ratio
%% define frequency
w1 = 3.48; %% frequency of structure
%% define damping ratio of structure
r1 = 0.01; %c1/(2*m1*w1);
%% define ground acceleration
ugdd = interp1(tdata,ydata,t);
%% Equation to solve
dydt = [y(2) -ugdd-(2*r1*w1*y(2))-((w1)^2*y(1))].';
end

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by