필터 지우기
필터 지우기

'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 (최근 30일)
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')

답변 (1개)

Torsten
Torsten 2022년 3월 9일
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by