.net - Compute trajectory using unit of measure -
i learning f# , trying use first time concept of unit of measure. have following questions:
the last let (variable y in getposition function gives me following error: "the unit of measure ''u ^ 2 m/second' not match unit of measure 'm'". there wrong in formula or usage os unit of measure?
i using unit of measures defined in microsoft.fsharp.data.unitsystems.si. there way not specify use shorter version of name? (e.g. unitnames.second vs second).
i have use function cos , sin. these 2 functions expect float, not float. use languageprimitives.floatwithmeasure convert float unit of measure. way that? makes code verbose.
thanks!
open system open microsoft.fsharp.data.unitsystems.si module generalballistictrajectory = [<measure>] type radian let gravitationalacceleration : float<unitnames.metre/unitnames.second^2> = 9.80665<unitnames.metre/unitnames.second^2> let getposition (angle: float<radian>) (velocity: float<unitnames.metre/unitnames.second>) (t: float<unitnames.second>) = let x = velocity * t * (cos (float angle) |> languageprimitives.floatwithmeasure<unitnames.metre/unitnames.second>) let abc = (0.5 * gravitationalacceleration) * t * t // returns float<unitnames.metre> // unit of measure 'unitnames.metre' not match unit of measure 'unitnames.metre ^ 2/unitnames.second' let y = (velocity * t * (sin (float angle) |> languageprimitives.floatwithmeasure<unitnames.metre/unitnames.second>)) - abc (x, y)
you can use shorter names adding
open microsoft.fsharp.data.unitsystems.si.unitnames
to file.
as error, it's not clear why converting result of sin
call measure type, since velocity * t
has same measure type (meter) abc
. following appears want:
open system open microsoft.fsharp.data.unitsystems.si open microsoft.fsharp.data.unitsystems.si.unitnames module generalballistictrajectory = [<measure>] type radian let gravitationalacceleration : float<metre/second^2> = 9.80665<metre/second^2> let getposition (angle: float<radian>) (velocity: float<metre/second>) (t: float<second>) = let x = velocity * t * (cos (float angle) |> languageprimitives.floatwithmeasure<metre/second>) let abc = (0.5 * gravitationalacceleration) * t * t // returns float<unitnames.metre> let y = (velocity * t * (sin (float angle))) - abc (x, y)
Comments
Post a Comment