Help with writing my code as pseudocode

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 commentaires

No need for the help but if someone could let me know if this looks right that would be great.
PROGRAM ModelRocket
m = 0.5;
Fthrust = 160;
g = 9.81;
vChute = -20;
tEngineCut = 0.15;
v = 0;
t = 0;
h = 0;
Dt = 0.01;
i = 1; v(i) = 0; h(i) = 0; t(i) = 0;
WHILE t(i) < tEngineCut
DO i = i + 1;
t(i) = t(i-1) + Dt;
v(i) = a1*t(i);
h(i) = 0.5*a1*t(i)^2;
ENDWHILE
v1 = v(i);
h1 = h(i);
t1 = t(i);
WHILE v(i) > vChute
DO i = i + 1;
t(i) = t(i-1) + Dt;
v(i) = v1 - g * (t(i)-t1);
h(i) = h1 + v1 * (t(i)-t1) - 0.5 * g * (t(i)-t1)^2;
ENDWHILE
v2 = v(i);
h2 = h(i);
t2 = t(i);
WHILE h(i) > 0
DO i = i + 1;
t(i) = t(i-1) + Dt;
v(i) = vChute;
h(i) = h2 + vChute * (t(i)-t2);
ENDWHILE
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');
ENDPROGRAM
Walter Roberson
Walter Roberson le 19 Nov 2023
Modifié(e) : Walter Roberson le 19 Nov 2023
There is no fixed rules for pseudocode, but it should generally be more descriptive and less procedural. If you are using array indexing extensively like you are, then you are probably getting too much like "code" and not enough like "pseudo"
Example: instead of writing
t(i) = t(i-1) + Dt;
you could be writing something like
add Dt to previous time to get new time
When they ask for pseudocode, they are probably looking for you to describe the algorithm in enough detail that they can tell that you understand the algorithm.
(Incidentally, one of the reasons to do that is that described algorithms are going to vary in text a lot more than uncommented procedural code like you posted. Yes, part of the reason to ask for pseudocode is to reduce the chance that you are cheating by copying someone else's code.)
Oscar Kinsella
Oscar Kinsella le 19 Nov 2023
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!
Quite frequently, people use flowcharts to elaborate their pseudo codes.

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by