My code keeps coming up with "Index Exceeds Array Bounds" help?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2018-4-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!