ERROR: Attempted to access dfi(3); index out of bounds because numel(dfi)=2.
이전 댓글 표시
Hello, this is the program I am talking about:
clc;
clear all;
% Vhodni podatki
Lz=0.5; %[m]
k=30; %[N/m]
g=9.81; %[m/s^2]
m=0.2; %[kg]
Tc=100; %[s] Čas celotnega opazovanega intervala
dt=0.001; %[s] Dolžina časovnega intervala od katerega je tudi odvisna napaka pri integriranju po Eulerju
B=0.05; %[N/(m*s)]
% Vodilni enačbi
ar=@(r,dr,fi,dfi) 1/m*(m*r*dfi^2-k*(r-Lz)+m*g*cos(fi)-B*dr);
af=@(r,dr,fi,dfi) 1/(m*r)*(-m*2*dr*dfi-m*g*sin(fi)-B*dfi*r);
% Začetni pogoji
rz=Lz;
drz=0;
fiz=pi/4;
dfiz=0;
% Stanje prve točke
t(1)=0;
r(1)=rz;
fi(1)=fiz;
dr(1)=drz;
dfi(1)=dfiz;
Fur(1)=B*dr(1);
Fuf(1)=B*r*dfi(1);
nihaj(1)=0;
ddr(1)=ar(r(1),fi(1),dr(1),dfi(1));
ddfi(1)=af(r(1),fi(1),dr(1),dfi(1));
i=2;
while nihaj<8;
t(i)=t(i-1)+dt;
r(i)=r(i-1)+dt*dr(i-1);
fi(i)=fi(i-1)+dt*dfi(i-1);
dfi(i)=dfi(i-1)+dt*ddfi(i-1);
dr(i)=dr(i-1)+dt*ddr(i-1);
ddr(i-1)=ar(r(i-1),dr(i-1),fi(i-1),dfi(i-1));
ddfi(i-1)=af(r(i-1),dr(i-1),fi(i-1),dfi(i-1));
i=i+1;
if sign(dfi(i))~=sign(dfi(i-1));
nihaj=nihaj+1;
end
end
T=t(end); % Čas 3.5 nihajev
Any1 has a clue where could be the problem? I keep getting the error above...
Regards
댓글 수: 5
Image Analyst
2013년 10월 19일
편집: Image Analyst
2013년 10월 19일
I'm not sure what about "Attempted to access dfi(3); index out of bounds because numel(dfi)=2" do you not understand. You can access dfi(1), or dfi(2), but not dfi(3) because there aren't that many elements in dfi.
mcluka
2013년 10월 19일
Image Analyst
2013년 10월 19일
What few comments do exist are in a language that I don't understand. The rest of it is a confusing alphabet soup of variables that I have almost no hope of following. Why don't you ask the author of the code?
mcluka
2013년 10월 20일
채택된 답변
추가 답변 (1개)
Anthony
2013년 10월 20일
change
i=i+1;
if sign(dfi(i))~=sign(dfi(i-1));
nihaj=nihaj+1;
end
to
if sign(dfi(i))~=sign(dfi(i-1));
nihaj=nihaj+1;
end
i=i+1;
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!