missing/incorrect use of math operators?

2 ビュー (過去 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 Center および File ExchangeGNC and Avionics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by