Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
153 views

Pseudocode Assignment

1. The document describes a pseudocode algorithm to calculate the launch angle needed for a projectile to reach a given maximum height. The algorithm uses iterative steps to calculate the height achieved at increasing launch angles until it exceeds the maximum height. 2. An example is shown applying the algorithm manually to calculate that a launch angle of 45 degrees is needed to reach a maximum height of 2.5 meters. 3. The launch angle is also calculated analytically, giving a result of 44.43 degrees, which is very close to the algorithmic solution, validating the pseudocode approach.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views

Pseudocode Assignment

1. The document describes a pseudocode algorithm to calculate the launch angle needed for a projectile to reach a given maximum height. The algorithm uses iterative steps to calculate the height achieved at increasing launch angles until it exceeds the maximum height. 2. An example is shown applying the algorithm manually to calculate that a launch angle of 45 degrees is needed to reach a maximum height of 2.5 meters. 3. The launch angle is also calculated analytically, giving a result of 44.43 degrees, which is very close to the algorithmic solution, validating the pseudocode approach.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Batayen, Christian Jade O.

August 14, 2019

BS in Chemical Engineering II

Machine Exercise I

1. Pseudocode for Landing Distance of Projectile

Step 1: Start at a time value of t=0 and h=0

Step 2: Increase time by adding small value ∆t to t (e.g., tnew=t + ∆t).


1
Step 3: Plug the new value of tnew into ℎ(𝑡) = 𝑣𝑡 sin 𝜃 − 2
𝑔𝑡 2 to get a new value of h, in which we
will call as hnew.

Step 4: Compare hnew with 0:

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 𝑔

We can now begin with the pseudocode.

Step 1: Start at a value of 𝜃=0, v=10, g=9.8, and h=0.

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.

Step 4: Compare hmax=2.5 and 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’.

Loop 𝜽 𝜽𝒏𝒆𝒘 𝒉 𝒉𝒏𝒆𝒘 Decision


hnew<2.5;
1 0 5 0 0.03875573211 loop back to
Step 2
hnew<2.5;
2 5 10 0.03875573211 0.1538453551 loop back to
Step 2
hnew<2.5;
3 10 15 0.1538453551 0.3417719291 loop back to
Step 2
hnew<2.5;
4 15 20 0.3417719291 0.5968254002 loop back to
Step 2
hnew<2.5;
5 20 25 0.5968254002 0.9112560977 loop back to
Step 2
hnew<2.5;
6 25 30 0.9112560977 1.275510204 loop back to
Step 2
hnew<2.5;
7 30 35 1.275510204 1.678520043 loop back to
Step 2
hnew<2.5;
8 35 40 1.678520043 2.108040363 loop back to
Step 2
hnew>2.5;
accept as
9 40 45 2.108040363 2.551020408
target data;
end algorithm
The last part of the problem requires us to find the value of the angle through more traditional
analytical methods. Solving for the value of 𝜃 analytically, we perform the following:

Given:

v=10 m/s h=2.5 m g=9.8 m/s2

Solution:
1 𝑣 2 sin2 𝜃
Using the equation ℎ(𝜃) = 2 𝑔
which we derived previously, we plug in the given
values, such that:

1 𝑣 2 sin2 𝜃
ℎ(𝜃) =
2 𝑔

1 (10 𝑚/𝑠)2 sin2 𝜃


2.5 𝑚 =
2 9.8 𝑚/𝑠 2

(2.5 𝑚)(9.8 𝑚/𝑠 2 )(2) = (10 𝑚/𝑠)2 sin2 𝜃

(2.5 𝑚)(9.8 𝑚/𝑠 2 )(2)


= sin2 𝜃
(10 𝑚/𝑠)2

(2.5 𝑚)(9.8 𝑚/𝑠 2 )(2)


√ = sin 𝜃
(10 𝑚/𝑠)2

(2.5 𝑚)(9.8 𝑚/𝑠 2 )(2)


θ = sin−1 √
(10 𝑚/𝑠)2

(2.5 𝑚)(9.8 𝑚/𝑠 2 )(2)


θ = sin−1 √
(10 𝑚/𝑠)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
𝑑𝑡

[3] 𝑥(𝑡) = 𝑣𝑡 cos 𝜃 Horizontal Displacement

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:

Equating equation [2] to t


𝑑ℎ(𝑡)
= 𝑣 sin 𝜃 − 𝑔𝑡
𝑑𝑡

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 1: Start at a value of 𝜃=0, g=9.8, x=8 and h=0.

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.

Step 4: Compare hreq=5 and 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 𝜃’.

Loop 𝜽 𝜽𝒏𝒆𝒘 𝒉 𝒉𝒏𝒆𝒘 Decision


hnew<5;
1 0 5 0 0.3499546541 loop back to
Step 2
hnew<5;
2 5 10 0.3499546541 0.7053079228 loop back to
Step 2
hnew<5;
3 10 15 0.7053079228 1.07179677 loop back to
Step 2
hnew<5;
4 15 20 1.07179677 1.455880937 loop back to
Step 2
hnew<5;
5 20 25 1.455880937 1.865230633 loop back to
Step 2
hnew<5;
6 25 30 1.865230633 2.309401077 loop back to
Step 2
hnew<5;
7 30 35 2.309401077 2.800830153 loop back to
Step 2
hnew<5;
8 35 40 2.800830153 3.356398525 loop back to
Step 2
hnew<5;
9 40 45 3.356398525 4.0000000 loop back to
Step 2
hnew<5;
10 45 50 4.0000000 4.76701437 loop back to
Step 2
hnew>5;
accept as
11 50 55 4.76701437 5.712592027
target data;
end algorithm
We then apply our last step for the algorithm, which is to take the mean angle value of the last two
derived values and consider it our target minimum launch angle.
𝜃 + 𝜃𝑛𝑒𝑤
𝜃𝑡𝑎𝑟𝑔𝑒𝑡 =
2
50° + 55°
𝜃𝑡𝑎𝑟𝑔𝑒𝑡 =
2
𝜃𝑡𝑎𝑟𝑔𝑒𝑡 = 52.5°

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.

You might also like