In a paper, V.R. Morrison discusses an interesting model of a frisbee. The author derives the equations governing the position (x, y), velocity (x’, y’) and acceleration (x’’, y’’) of a frisbee as:
CD(α) is a drag coefficient at angle of attack (AoA) α, and CL(α) is the lift coefficient at AoA α, area and mass are, you guessed, the area and the mass of the frisbee, g is the gravitational acceleration, and ρ is the density of air.
To solve these equations and compute the frisbee’s trajectory, the paper submits a Java program implementing the Euler’s method to integrate the differential equations.
While Java is perfectly capable of solving these equations, let us look at a couple of issues.
In the code we see items like:
Code like this makes an assumption that the value of AoA (ALPHA) is defined in specified units – degrees. Such assumptions are implicit. Namely, there is nothing that will alert user if he/she specifies ALPHA to be radians or even kilograms!
Does the Java code look anything like the equations above? Which is easier to read?
No units checking and poor readability results in hard to catch mistakes
Looking carefully at the equations above, notice that mass is missing in the dominator of cd! Consequently the results are off. However, had we checked the units, we’d see that they don’t match, leading us to review the equation and find the problem.
Here is how we address this in PTC Mathcad. Mathcad supports programming, so the same Java code can be easily transcribed into a Mathcad program. We immediately see two advantages: readability and unit checking. Making the same mistake as in the original Java code will yield a unit error.
PTC Mathcad solution
Here is the complete program:
Programming in PTC Mathcad! What’s up with that?
When I talk about the PTC Mathcad roadmap, I say things like “more problem solving, less programming”, etc. So, why are we talking about Mathcad programs here? Do we have to write programs to solve differential equations? Of course not! This is Mathcad after all!
I used the programming feature to contrast PTC Mathcad and Java. We can skip the Euler’s method and solve the differential equations directly. Here is how the solution looks.
There is nothing to it. Equation as you would write in your notebook, units and all! By doing so, we find (again) that the results don’t match! Equation
is missing a factor of ½.
Using formulas that are easy to read and closer to the problem specification, not only makes the calculations look better, but also reduces the number of errors.
Note: You can use PTC Mathcad Express to view these documents. However, to calculate, you will need a licensed version.
Stay tuned for the worksheet that solved the same problem using features only available in PTC Mathcad Express…