My code keeps coming up with "Index Exceeds Array Bounds" help?
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!