mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 15:47:01 +08:00
unit: add more complex example
This commit is contained in:
@@ -27,3 +27,23 @@ func ExampleNewDimension() {
|
|||||||
|
|
||||||
// Output: 0.1 tree m^-2
|
// Output: 0.1 tree m^-2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Example_horsepower() {
|
||||||
|
// One mechanical horsepower ≡ 33,000 ft-lbf/min.
|
||||||
|
foot := unit.Length(0.3048)
|
||||||
|
pound := unit.Mass(0.45359237)
|
||||||
|
|
||||||
|
gravity := unit.New(9.80665, unit.Dimensions{unit.LengthDim: 1, unit.TimeDim: -2})
|
||||||
|
poundforce := pound.Unit().Mul(gravity)
|
||||||
|
|
||||||
|
hp := ((33000 * foot).Unit().Mul(poundforce)).Div(unit.Minute)
|
||||||
|
fmt.Println("1 hp =", hp)
|
||||||
|
|
||||||
|
watt := unit.New(1, unit.Dimensions{unit.MassDim: 1, unit.LengthDim: 2, unit.TimeDim: -3})
|
||||||
|
fmt.Println("W is equivalent to hp?", unit.DimensionsMatch(hp, watt))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
//
|
||||||
|
// 1 hp = 745.6998715822701 kg m^2 s^-3
|
||||||
|
// W is equivalent to hp? true
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user