missing/incorrect use of math operators?
Show older comments
Good evening,
I am new to matlab, and was wondering if someone could look at my code to see if I am incorrectly using/missing some sort of math operator (i.e. I've noticed sometimes you need a ./ verses a / for divison).
My code produces a table however, the time of flight column should be consistantly increasing in a value, and my striking velocity values are too large. I am wondering if I am missing something in my code.
Thank you for your assistance
Below is my code:
k3 = 0.5;
Vx_o = 2296;
t = 0;
for i = 1:6
x(i) = (i-1)*200*3; % range in feet
Vx(i) = (sqrt(Vx_o) - ((k3/2)*x(i)))^2; % x velocity
t(i) = (x(i)/Vx_o)*sqrt(Vx_o/Vx(i)); % time
end
T = table(x(:)/3, x(:), Vx(:), t(:), 'VariableNames',{'yards', 'feet', 'striking velocity', 'time of flight'})
Accepted Answer
More Answers (1)
Peter Perkins
on 19 Nov 2020
Jocelyn, modulo Geoff's concerns, I think your whole loop can be done as
x = 200*3*(0:5)';
Vx = (sqrt(Vx_o) - ((k3/2).*x))^2;
t = (x./Vx_o).*sqrt(Vx_o./Vx);
and then I guess
t = cumsum(t);
Also, if time should be increasing, that suggests that maybe T should be a timetable rather than a table.
Categories
Find more on MATLAB 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!