exceeds the number of array
1 view (last 30 days)
Show older comments
Jocelyn
on 16 Nov 2020
Commented: Walter Roberson
on 16 Nov 2020
Hi,
I keep getting error messages about line 32 (Vy (i) = line). I double checked the brackets and they seem to match up. Below is the error message I am recieving.
Index exceeds the number of array elements (1).
Error in CC551_A5_P3 (line 32)
Vy(i) = Vx(i)*(tand(phi_o(i))-(g*t(i)/Vx_o)*(1+(0.5*Vx_o*k1*t(i)))); % y direction velocity
Thank you!
% Given Information In Problem
Vx_o = 2060; % muzzle velocity (ft/s)
k1 = 0.00082; % (1/ft) note: converted from 0.00025 (1/m)
p = 0.0751; % (lbm/ft^3) row - standard sea level met data
a = 1120; % (ft/s) standard sea level met data
% initial conditions
t = 0; % (s)
g = 32.174; %gravitational constant (ft/sec^2) [at sea level]
%setting up inital conditions at i = 1
t(1) = 0;
Vx(1) = 2060;
x(1) = 0;
phi_o(1) = 0;
phi(1) = 0;
for i = 1:6
x(i)= (i-1)*200*3; % x3 = converting range from yards to feet
Vx(i) = Vx_o*exp(-k1*x(i)); % striking velocity
t(i) = ((x(i)/Vx_o)*((Vx_o/Vx(i))-1))/log(Vx_o/Vx(i)); % time of flight
Vy(i) = Vx(i)*(tand(phi_o(i))-(g*t(i)/Vx_o)*(1+(0.5*Vx_o*k1*t(i)))); % y direction velocity
phi(i) = (atand(Vy(i)/Vx(i))); % impact angle
phi_o(i) = atand(tand(phi(i))+((g*t(i)/Vx_o)*(0.5*(1+(Vx_o/Vx(i))))));
end
Range_Table = table(x(:)/3, Vx(:), t(:), phi_o(:), phi(:),...
'VariableNames',{'yards', 'impact velocity (ft/s)', 'time of flight (s)', 'inital QE angle (degrees)', 'impact angle (degrees)'})
0 Comments
Accepted Answer
Walter Roberson
on 16 Nov 2020
Edited: Walter Roberson
on 16 Nov 2020
Vy(i) = Vx(i)*(tand(phi_o(i))-(g*t(i)/Vx_o)*(1+(0.5*Vx_o*k1*t(i)))); % y direction velocity
That needs phi_o(i) to exist. But
phi(i) = (atand(Vy(i)/Vx(i))); % impact angle
phi_o(i) = atand(tand(phi(i))+((g*t(i)/Vx_o)*(0.5*(1+(Vx_o/Vx(i))))));
it does not exist until a few lines later.
Consider the possibility that you should be iterating i=2:6 or i=2:7 and that you should be indexing at (i-1) in places.
2 Comments
Walter Roberson
on 16 Nov 2020
t(i) = ((x(i-1)/Vx_o)*((Vx_o/Vx(i-1))-1))/log(Vx_o/Vx(i-1)); % time of flight
when Vx_o == Vx(i-1) then Vx_o/Vx(i-1) is 1, and log(1) is 0, and you have a division by 0.
Vx(i) = Vx_o*exp(-k1*x(i-1)); % striking velocity
When i = 1 then (i-1)*something is 0 so x(i) is 0, and exp(-k1*0) is 1 so Vx(i) will be the same as Vx_o.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!