필터 지우기
필터 지우기

Why do I get the error message "Index exceeds matrix dimensions."

조회 수: 1 (최근 30일)
Martin
Martin 2016년 1월 27일
답변: Abhisek Roy 2016년 2월 4일
The complete error message:
Index exceeds matrix dimensions.
Error in @(t,u,g,L)[u(2);-g/L*sin(u(1))]
Error in @(t,u)f(t,u,g,L)
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
The questioning is about a pendulum that have different starting values(10,30,....,170)of angle phi0. and I aren´t able to solv it. Thanks in advance :)
The code:
L=0.1; g=9.82;
phi0=linspace(10*pi/180,170*pi/180,9);
f=@(t,u,g,L)[u(2); -g/L*sin(u(1))];
tspan=linspace(0,1,200);
o=zeros(size(phi0));
u0=[phi0;o];
options=odeset('Events',@funevent);
for i=1:1
[t,U]=ode45(@(t,u)f(t,u,g,L),tspan,u0(i),options);
end
subplot(1,2,1), plot(t,U(:,1),'g')
subplot(1,2,2), plot(U(:,1),U(:,2),'g')

답변 (1개)

Abhisek Roy
Abhisek Roy 2016년 2월 4일
Hi Martin,
The error occurred as u0 provided to ode45 should be a [2,1] vector as the dynamics has two states. So change u0(i) to u0(:,i) and you should be able to integrate it. Also you have not defined funevent function, so define it before you run again, or you can remove it also.

카테고리

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