ERROR: Attempted to access dfi(3); index out of bounds because numel(dfi)=2.
1 回表示 (過去 30 日間)
古いコメントを表示
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 日
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?
採用された回答
その他の回答 (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;
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!