ERROR: Attempted to access dfi(3); index out of bounds because numel(dfi)=2.

1 回表示 (過去 30 日間)
mcluka
mcluka 2013 年 10 月 19 日
回答済み: mcluka 2013 年 10 月 20 日
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
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
mcluka 2013 年 10 月 20 日
I am the author of the code, the code just doesnt work. The program counts swings of a mass connected to a spring, the spring is then connected to a line, the total length of the spring+line equals Lz, B is the coefficient of wind resistance, so there is also wind resistance force, the rest is just physics. What I wanted to do is to count swings in a time lapse of Tc, the program would count the swings and stop at 3.5 swings, then i would see the time of 3.5 swings.
A little slovenian dictionary: nihaj=swing, stanje prve tocke=information for the first point, začetni pogoji=starting properties, vhodni podatki=main information
regards

サインインしてコメントする。

採用された回答

mcluka
mcluka 2013 年 10 月 20 日
Never mind, fixed the problem :)
regards

その他の回答 (1 件)

Anthony
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;

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by