Entering Scientific Formulas

I have developed this technique to use when I program long formulas. First, I declare descriptive variables for the mathematical elements. I prototype the formula using the digit “1” as a place holder for the variables. This allows me to review the structure of the formula and make sure it compiles. I keep a copy of the formula as an inline comment.I replace the place holders with the variable by using cut and paste. This is an example that calculates the volume of a cap of a sphere:

 Public Const PI = 3.141592653589Dim CapVolume As SingleDim SphereRadius As SingleDim CapHeight As Single'Sample valuesSphereRadius = 9.35CapHeight = 3.33'Formula as prototype which is left in 'the code for the volume of the cap of a sphere'CapVolume = PI * 1 * 1 * (3 * 1 - 1) / 3CapVolume = PI * CapHeight * CapHeight _	* (3 * SphereRadius - CapHeight) / 3'Reality checkDebug.Print CapVolume
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: