missing/incorrect use of math operators?

조회 수: 1 (최근 30일)
Jocelyn
Jocelyn 2020년 11월 12일
답변: Peter Perkins 2020년 11월 19일
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'})

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 11월 13일
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.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2020년 11월 19일
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.

카테고리

Help CenterFile Exchange에서 GNC and Avionics에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by