My code keeps coming up with "Index Exceeds Array Bounds" help?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
n = 0;
t = 0;
deltat = 0.1;
m = 0.44;
Cd = 0.05;
p = 1.29;
Ra = 0.135;
%Find b using the rearranged formula for circumference of a circle.
b = 0.6/(pi()*2);
A = pi()*Ra*b;
% Pre set random values for testing code
x = [12,12,12];
deltat = [0.1];
agravity = [0,0,-9.81];
v = [2,2,2];
vwind = [3,1,2];
vdrag = [2,1,2];
fdrag = [3,2,3];
while x<=100
n = n + 1;
t(n+1) = t(n) + deltat;
x(n+1) = x(n) + v(n).*deltat;
v(n+1) = v(n) + (agravity(n).*deltat);
end
0 Kommentare
Antworten (1)
Walter Roberson
am 30 Apr. 2018
You have
agravity = [0,0,-9.81];
so agravity is length 3. You are not storing new agravity entries as you go along like you are for t, x, v, so when you reach n = 4, agravity(n) will be an error.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!