フィルターのクリア

Help with writing my code as pseudocode

41 ビュー (過去 30 日間)
Oscar Kinsella
Oscar Kinsella 2023 年 11 月 18 日
コメント済み: Sulaymon Eshkabilov 2023 年 11 月 19 日
I have attached my code below. I have completed the code for my college assignment however part of the assignment is to submit my code as psuedocode. I have an idea of what psuedocode is but I cannot figure how to write it. Especially for the code I have written. If someone could explain and help with this I would appreciate it.
Known + Initial Values
% Known Values
m = 0.5; % Mass of the model rocket in Kg
Fthrust = 160; % Force of the engine fuel pushing the rocket at take off
g = 9.81; % Acceleration due to gravity
vChute = -20; % Velocity of the rocket when the auto parachute is deployed on way down
tEngineCut = 0.15; % Total time before engine cuts in seconds
% Initial Values @ t=0
v = 0; % Velocity
t = 0; % Time
h = 0; % Height
Dt = 0.01; % Time step size in seconds
i = 1; v(i) = 0; h(i) = 0; t(i) = 0; % Making sure the first values for each variable in the index equal 0
Segment 1 - Rocket Take Off
% While loop to run all calculations from t=0 -> t=0.15 with steps of 0.01
a1 = (Fthrust - m*g)/m; % Acceleration calculation
while t(i) < tEngineCut % Run while loop until the engine cuts out after 0.15s
i = i + 1; % Increasing n by 1
t(i) = t(i-1) + Dt; % Height Update
v(i) = a1*t(i); % Velocity Update
h(i) = 0.5*a1*t(i)^2; % Height Update
end
v1 = v(i); % Allow the values v1,h1,t1 to equal the latest value of v,h,t after segment 1 while loop is completed
h1 = h(i); % Also records the value for v,h and t when the rocket is at its peak height
t1 = t(i);
SEGMENT 2 - ROCKET FREE FALL
% While loop to calculate the velocity, height and time as the rocket
% decelerates
while v(i) > vChute % all values with time incriments of 0.01 until velocity hits 20 m/s
i = i + 1; % Increasing n by 1
t(i) = t(i-1) + Dt; % Time Update
v(i) = v1 - g * (t(i)-t1); % velocity update for free fall - force of gravity, slowing down
h(i) = h1 + v1 * (t(i)-t1) - 0.5 * g * (t(i)-t1)^2; % Height Update
end
v2 = v(i); % Allow the values v2,h2,t2 to equal the latest value of v,h,t after segment 2 while loop is completed
h2 = h(i); % Also records the value for v,h and t when the parachute opens
t2 = t(i);
SEGMENT 3 - ROCKET DECENDING WITH PARACHUTE OPEN TILL THE GROUND
% While loop to calculate the height at every 0.01s with a constant
% velocity of -20 m/s
while h(i) > 0 % Run while loop until rocket hits the ground
i = i + 1; % Increasing n by 1
t(i) = t(i-1) + Dt; % Time Update
v(i) = vChute; % The velocity stays constant at -20 m/s^2 as the parachute will not allow it to go any faster
h(i) = h2 + vChute * (t(i)-t2); % Update height
end
PLOT GRAPHS
% Plot graph of time vs height
plot(t,h,t2,h2,'o');
hold on
plot(t,v,t2,v2,'o');
hold off
xlabel('Time (s)');
ylabel('Height (m) / Velocity (m/s)');
title('Time (s) plotted against the Height and Velocity of model rocket (m)/(m/s)');
legend('o = chute opens');
  4 件のコメント
Oscar Kinsella
Oscar Kinsella 2023 年 11 月 19 日
that makes a lot of sense, thanks for the help. I have rewriten the code in the same format but I have writen it as an english sentence instead. Lecture looked at it and said it perfect. Thank you for the help!
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 11 月 19 日
Quite frequently, people use flowcharts to elaborate their pseudo codes.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by