Pseudocode Assignment
Pseudocode Assignment
BS in Chemical Engineering II
Machine Exercise I
If hnew>0, then the cannonball is still in flight. Set t=tnew, h=hnew , and return to Step 2
If hnew<0, then the cannon ball has reach the ground, however, the final time is in between h and
hnew.
Step 5: Assume that the final time occurs at the height in between the interval of h and hnew where
ℎ+ℎ𝑛𝑒𝑤
hnew<0. Identify the target value t as the value of 𝑡 =
2
Step 6: Plug the target value t into 𝑥(𝑡) = 𝑣𝑡 𝑐𝑜𝑠𝜃 to find the horizontal distance travelled by the
cannonball.
2. Problem 1.3
Before we begin with the pseudocode proper, we begin the solution by setting up the equations in
order to eliminate a value which is unknown. Given that:
1
[1] ℎ(𝑡) = 𝑣𝑡 sin 𝜃 − 2
𝑔𝑡 2 Vertical Displacement
𝑑ℎ(𝑡)
[2] 𝑑𝑡
= 𝑣 sin 𝜃 − 𝑔𝑡 Vertical Velocity
Since we understand that the first derivative of the Vertical Displacement Equation [1] will yield the
Vertical Velocity Equation [2], and that the point at which the value is zero is a local maximum, we
let Equation 2 be equal to zero, and we equate it to t, such that at time t, the velocity is 0 and the
projectile has achieved peak height.
𝑑ℎ(𝑡)
= 𝑣 sin 𝜃 − 𝑔𝑡
𝑑𝑡
0 = 𝑣 sin 𝜃 − 𝑔𝑡
𝑔𝑡 = 𝑣 sin 𝜃
𝑣 sin 𝜃
𝑡=
𝑔
We then take the value of t, and plug it into Equation 1 in order to get a new equation for the
height, which will now depend on the angle 𝜃, such that:
1 2
ℎ(𝑡) = 𝑣𝑡 sin 𝜃 − 𝑔𝑡
2
𝑣 sin 𝜃 1 𝑣 sin 𝜃 2
ℎ(𝜃) = 𝑣 sin 𝜃 − 𝑔 ( )
𝑔 2 𝑔
𝑣 2 sin2 𝜃 1 𝑣 2 sin2 𝜃
ℎ(𝜃) = −
𝑔 2 𝑔
𝑣 2 sin2 𝜃 1
ℎ(𝜃) = (1 − )
𝑔 2
1 𝑣 2 sin2 𝜃
ℎ(𝜃) =
2 𝑔
Step 2: Increase launch angle by adding a value ∆𝜃=5° to 𝜃 (e.g., 𝜃new= 𝜃 + ∆𝜃), but never reaching
90° or higher.
1 𝑣 2 sin2 𝜃
Step 3: Plug the new value of 𝜃new into ℎ(𝜃) = 2 𝑔
to get a new value of h, in which we will call
as hnew.
If hmax>hnew, then the launch angle needed to reach the desired height has not been reached yet.
Set 𝜃 = 𝜃new and return to Step 2.
If hmax<hnew, then the launch angle needed to reach the peak height of 2.5 is somewhere
between h and hnew. End algorithm.
Step 5: Assume that the angle needed occurs when the height hmax<hnew. Identify the angle target
value 𝜃.
We then subject the pseudocode with some manual calculations, and we come up with the
following data. Note that the condition for the decision is defined by the statement, ‘if hnew<2.5,
then let 𝜃new= 𝜃 + ∆𝜃 and undergo loop back to step 2, if hnew≥2.5, then assume 𝜃new as the target
value and end algorithm’.
Given:
Solution:
1 𝑣 2 sin2 𝜃
Using the equation ℎ(𝜃) = 2 𝑔
which we derived previously, we plug in the given
values, such that:
1 𝑣 2 sin2 𝜃
ℎ(𝜃) =
2 𝑔
θ = 44.427004° 𝑜𝑟 44.23°
Comparing the algorithmic solution of θ = 45° with the analytical solution θ = 44.43°, we get an
error value of 𝜖 = 0.57°, and a percent error 𝛿 = 1.28%. Since 𝛿 is very small, and is thus negligible,
we can say that the algorithmic solution is a good approximation of the true value, and is therefore
acceptable.
3. Problem 1.4
Again, we are faced with the same model for the flight path of the projectile in Problem 1.3. Only
this time, we are asked to clear a wall 5 meters tall at a distance of 8 meters from the launching
point. Here we are asked to determine the minimum value for the launch angle, and find a way to
eliminate the initial velocity, that would allow the projectile to clear the wall. Before we begin with
the pseudocode proper, we begin the solution by setting up the equations in order to eliminate a
value which is unknown. Given that:
1
[1] ℎ(𝑡) = 𝑣𝑡 sin 𝜃 − 𝑔𝑡 2 Vertical Displacement
2
𝑑ℎ(𝑡)
[2] = 𝑣 sin 𝜃 − 𝑔𝑡 Vertical Velocity
𝑑𝑡
Since we understand that the first derivative of the Vertical Displacement Equation [1] will yield the
Vertical Velocity Equation [2], and that the point at which the value is zero is a local maximum, we
let Equation 2 be equal to zero, and we equate it to t, such that at time t, the velocity is 0 and the
projectile has achieved peak height. We also understand that when the projectile reaches peak
height, it is halfway on its horizontal path, thus, the Horizontal Displacement Equation [3] at time t is
related to the other 2 equations, such that:
0 = 𝑣 sin 𝜃 − 𝑔𝑡
𝑣 sin 𝜃 = 𝑔𝑡
𝑣 sin 𝜃
𝑡=
𝑔
Equating equation [3] to t
𝑥(𝑡) = 𝑣𝑡 cos 𝜃
𝑥(𝑡)
𝑡=
𝑣 cos 𝜃
Equating t according to equation [2] and equation [3]
𝑣 sin 𝜃 𝑥(𝑡)
=
𝑔 𝑣 cos 𝜃
𝑔 𝑥(𝑡)
𝑣2 =
sin 𝜃 cos 𝜃
Due to the nature of the equation where we have two variables unknown (the angle and the initial
velocity), we must eliminate one of aforementioned variables from the equation, then create a
pseudocode that will solve for it algorithmically. Below, we set up our final derivation for an
equation before we proceed with our pseudocode. Note that we borrowed a derivation from the
previous problem in order to make the solution more convenient (which is permissible since they
are modeled similarly).
1 𝑣 2 sin2 𝜃
ℎ(𝑡) =
2 𝑔
𝑔 𝑥(𝑡) 2
1 sin 𝜃 cos 𝜃 sin 𝜃
ℎ(𝜃) =
2 𝑔
1 𝑥(𝑡)
ℎ(𝜃) = sin 𝜃
2 cos 𝜃
1
ℎ(𝜃) = 𝑥(𝑡) tan 𝜃
2
We can now begin with the pseudocode.
Step 2: Increase launch angle by adding a value ∆𝜃=5° to 𝜃 (e.g., 𝜃new= 𝜃 + ∆𝜃), but never reaching
90° or higher.
1
Step 3: Plug the new value of 𝜃new into ℎ(𝜃) = 2 𝑥(𝑡) tan 𝜃 to get a new value of h, in which we will
call as hnew.
If hreq>hnew, then the height is still inadequate and the projectile will hit the wall. The launch
angle must still be increased. Set 𝜃 = 𝜃new and return to Step 2.
If hreq<hnew, then the launch angle needed to clear the wall of 5 meters will have a minimum
value located between h and hnew. End algorithm for 𝜃.
Step 5: Assume that the angle needed occurs between the angles at heights hreq and hnew. Identify
𝜃+𝜃𝑛𝑒𝑤
the minimum angle target value 𝜃𝑡𝑎𝑟𝑔𝑒𝑡 = 2
.
This particular data table is consistent with the pseudocode for deriving the minimum launch angle
requirement which is solved with some manual calculations. We come up with the following data.
Note that the condition for the decision is defined by the statement, ‘if hnew<5, then let 𝜃new= 𝜃 + ∆𝜃
𝜃+𝜃𝑛𝑒𝑤
and undergo loop back to step 2, if hnew>5, then assume 𝜃𝑡𝑎𝑟𝑔𝑒𝑡 = as the target value and
2
end algorithm for 𝜃’.
In conclusion, using the pseudocode we provided, the required minimum launch angle was
calculated to be 52.5° with a launch velocity that was negligible due to the way the equation is
stated. Due to the nature of the problem, it can be assumed that all values subsequent to 52.5° but
is less than 90°, which is launched at some maximum velocity, will no doubt clear past the wall 5
meters tall.
Since the problem didn’t specifically ask for the analytic value of the 𝜃𝑡𝑎𝑟𝑔𝑒𝑡 , giving an analytic
solution is just excessive. Nonetheless, should we attempt to solve for it, we will arrive at an angle
𝜃 = 51.34°. We get an error value of 𝜖 = 1.16°, and a percent error 𝛿 = 2.26%. Since 𝛿 is very
small, and is thus negligible, we can say that the algorithmic solution is a good approximation of the
true value, and is therefore acceptable.