Download or view Ethanol.frink in plain text format
/** This is a class that contains various calculations about ethanol (that is,
the usual drinking alcohol.)
Most functions are class-level functions meaning that you can call them
without an instance of the class.
Density calculations are deived from LeastSquaresFitAlc.frink
*/
class Ethanol
{
/** Given an ethanol-water mix with the given density (probably measured as
g/cm^3 and must have those dimensions,) returns the percentage of alcohol as a dimensionless number between 0 and 1. If the density is out of the
physical ranges of ethanol-water mixes (e.g. from 1 g/cm^3 at 0% alcohol
to 0.7939 g/cm^3 at 100% alcohol,) the behavior is currently undefined.
*/
class densityToPercent[density is mass_density] :=
{
x = density / (g/cm^3)
if x < 0.9244
p = 2541.808938140371 x^3 + -7511.267369943389 x^2 + 6924.229816881236 x + -1934.810793622680
else
if x < 0.97608
p = -71159.75090820634 x^3 + 197494.3009780669 x^2 + -183203.0689308734 x + 56856.10214464291
else
p = 15582.22157329863 x^3 + -37521.67546881218 x^2 + 27672.18981374326 x + -5732.705459313710
return p percent
}
/** Given an ethanol-water mix with the given percentage of ethanol
(measured as a dimensionless number between 0 and 1, that is, 80 proof
is 40% alcohol and the input should be 0.4), returns the density of the
mix (you can treat it as g/cm^3 )
If the percentage is not between 0 and 1, the behavior is currently
undefined.
You can call this like:
Ethanol.percentToDensity[40 percent] -> "g/cm^3"
which returns
"0.95182"
*/
class percentToDensity[percentAlcohol is dimensionless] :=
{
if (percentAlcohol < 0) or (percentAlcohol > 1)
println["Ethanol.percentToDensity: was passed a value not between 0% and 100%. Value was " + percentAlcohol]
x = percentAlcohol * 100
if x < 32
d = -5.049258448369746e-7 x^3 + 0.00002974600301202464 x^2 + -0.001592547961868473 x + 1.0000628175763
else
if x < 85
d = 8.942640260440939e-8 x^3 + -0.00003044191130699079 x^2 + 0.0004539612214965898 x + 0.9766798856308560
else
d = -0.000003136268563653715 x^3 + 0.0008056820001188939 x^2 + -0.07208147436198514 x + 3.081536420026518
return d (g/cm^3)
}
}
Download or view Ethanol.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen, eliasen@mindspring.com