Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Image Analyst
Image Analyst am 19 Okt. 2013
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 am 20 Okt. 2013
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

mcluka
mcluka am 20 Okt. 2013
Never mind, fixed the problem :)
regards

Weitere Antworten (1)

Anthony
Anthony am 20 Okt. 2013
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;

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by