Jaa


F#: Ballistics, Rocketry and Research 4/12/2009

In the previous post, I talked about the units of measurement class in Chris Smith’s BurnedLand program.  We are continuing down this path because units are an important part of most scientists and engineering disciplines.  The reason we are going down this path is that I am demonstrating how F# could have saved the Mars Climate Orbiter if this type of coding using dimensions had been used.  To do so, takes a bit of time, the loss of $200,000,000 in 1999 represents a great deal of money, even in the US, and it is a common error that plagues developers, engineers and scientists.  so the research part of these series of blogs is how Computer Science is reacting to the errors of the past, that is the Mars Climate Orbiter crash, rocketry via improving the ESTES rocket curriculum and ballistics because it is the basis for both.

Why continue using the BurnedLand program?  The BurnedLand is important because it illustrates the process of using Windows Presentation Foundation code and XAML written in C# with classes written in F#, and includes existing code that solves some parts of a ballistic problem, important parts.

In the previous post we discussed the process of defining units and the motivation to do so by examining the code in the class UnitsOfMeasure.fs.  (You might be asking: “Why are you using Chris Smith’s code instead of writing your own?”  Good question, I feel that we should READ code as well as write it.)

Now that the units have been defined, how do we utilize these units in other classes?  In the F# math.fs class you will see, that the class is declared using the “open” keyword, the “open” keyword is an import declaration (see chapter 8 of the referenced hyperlink).  In our BurnedLand example the unitsofmeasurement.fs is imported using the “open” keyword, this tells the class that to just in time compile the information on where the units of measurement class is stored in memory.  Now the units of measurement can be used in other classes.  

Here is the syntax that you use so that the units of measurement can be used in another class:

open UnitsOfMeasure

There other ways to implement units of measurement, Chris’ approach used a “manual” method that would be required if you where to use the US system of measurements such as feet, yard, etc. or other non-SI units of measurements.  It is similar because you must reference another class, this class is contained in a DLL and so there are some other steps you need to take:

Currently if you do an Import Declare using the keyword open, you will see that there are three items related to the Math namespace  image
Right click on the References of the F# project you are working on.  Select the Add Reference.  You will be adding an F# DLL in the next step image
Scroll down and select FSharp.Power.Pack image

Now you will see that the Math namespace has many more methods, fields, etc. than it did before.  If you scroll down you will see the letters SI, those are used for standard metric units.  If you need to utilize unity physical constants then use the component “Physical Constant”.Another good source for all of this is Andrew Kennedy’s blog. 

Not only do you get the metric units you also get physical constants.  Complete lists are found at:

Don’t select anything you only need to observe.

 

image

Ok, I hope this helps you understand better how to reference exisiting DLLs and class modules inside of classes, as well as how to use the unit of measurements to make sure your algorithms are dimensionally sound.

In the next post we will Read the code in the Math module, which is what I had intended for this entry, except that the units of measurement discussion always gets me very excited.

Technorati Tags: ESTES rockets,Units of Measurement,Dimensional Analysis,Engineering,Mars Climate Orbiter

Comments