missing/incorrect use of math operators?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jocelyn
el 12 de Nov. de 2020
Respondida: Peter Perkins
el 19 de Nov. de 2020
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'})
0 comentarios
Respuesta aceptada
Geoff Hayes
el 13 de Nov. de 2020
Jocelyn - why should the time of flight value be increasing in value? Is it because it is dependent upon the previous value? Do you want add the previous value to this current like
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
if i > 1
t(i) = t(i) + t(i-1); % is this what you want?
end
end
As for the striking velocity being too large, consider the line
Vx(i) = (sqrt(Vx_o) - ((k3/2)*x(i)))^2;
You are taking sqrt(Vx_o) (so the square root of some unit) and subtracting ((k3/2)*x(i)) (in some unit) I think that this is incorrect as you are subtracting values with different units. You will want to ensure that both have the same units before you subtract one from the other.
0 comentarios
Más respuestas (1)
Peter Perkins
el 19 de Nov. de 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.
0 comentarios
Ver también
Categorías
Más información sobre GNC and Avionics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!