필터 지우기
필터 지우기

'Index exceeds the number of array elements ' why this error is showing?

조회 수: 1 (최근 30일)
RAJKUMAR SAHA
RAJKUMAR SAHA 2022년 3월 2일
댓글: VBBV 2022년 3월 3일
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)
w = 6.981; %% Input natural frequencycy(rad/s)
%% define frequency
w1 = sqrt(k1/m1); %% frequency of structure
%% define damping ratio of structure
r1 = c1/(2*m1*w1);
%% define ground acceleration
ugdd = -A*w^2*sin(w*i);
%% Equation to solve
dydt = [y(4)
(-ugdd-(2*r1*w1*y(4))-((w1)^2*y(3)))];
%% To run mass spring damper system
i = 0:0.01:20;
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')

답변 (2개)

KSSV
KSSV 2022년 3월 2일
This line:
dydt = [y(4)
(-ugdd-(2*r1*w1*y(4))-((w1)^2*y(3)))];
expects y to be 1x4 vector, but your y is 1x2.

VBBV
VBBV 2022년 3월 2일
편집: VBBV 2022년 3월 2일
I = 0:0.1:20;
y = [0 0];
%% Solve using ode45
[tsol,ysol] = ode45(@my_ode_without_tld,[0 10],[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')
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)
w = 6.981; %% Input natural frequencycy(rad/s)
%% define frequency
w1 = sqrt(k1/m1); %% frequency of structure
%% define damping ratio of structure
r1 = c1/(2*m1*w1);
%% define ground acceleration
ugdd = -A*w^2*sin(w*I);
%% Equation to solve
dydt = [y(2) -ugdd-(2*r1*w1*y(2)-((w1)^2*y(1)))].';
%% To run mass spring damper system
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