'Index exceeds the number of array elements ' why this error is showing?
조회 수: 1 (최근 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)
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')
댓글 수: 0
답변 (2개)
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
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 Center 및 File Exchange에서 Transforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!