Documentation
¶
Overview ¶
Package mathem is a sub-package of the gophysics library.
Its porpuse is to make the most common Math calculations used for Physics.
Some of the most basic operations are radiants to degrees (and viceversa) conversions, area calculations, summatory, ecc...
Here is the documentation https://pkg.go.dev/github.com/Gabri432/gophysics/mathem
Index ¶
- Constants
- func ArithmeticMean(values ...float64) float64
- func CircleArea(radius float64) (area float64, measurementUnit string)
- func CosineSquare(angleInDeg float64) float64
- func DegToRad(angleInDeg float64) (radiants float64, measurementUnit string)
- func GeometricMean(values ...float64) float64
- func HarmonicMean(values ...float64) float64
- func Power10(base float64, power int) float64
- func PowerAt(base, power float64) float64
- func ProductOfSequence(startingValue, endingValue int, function func(value int) float64) (product float64)
- func RadToDeg(angleInRad float64) (degrees float64, measurementUnit string)
- func SineSquare(angleInDeg float64) float64
- func SphereVolume(radius float64) (volume float64, measurementUnit string)
- func StandardDeviation(values ...float64) float64
- func Summatory(startingValue, endingValue int, function func(value int) float64) (sum float64)
- func Variance(values ...float64) float64
Constants ¶
const (
//Greek Pi
Pi, GreekPi = 3.1415926535, Pi
//1 Radiant in degrees
Radiant = 57.2958
//Euler number
E = 2.71828
//Square root of 2
SquareRoot_2 = 1.41421
//Square root of 3
SquareRoot_3 = 1.73205
)
Variables ¶
This section is empty.
Functions ¶
func ArithmeticMean ¶ added in v0.17.0
Calculates the arithmetic mean of the user given values.
Example:
func main() { mathem.ArithemticMean(1,2,3,4,6) // (1+2+3+4+6)/5 => 16/5 == 3.2 }
func CircleArea ¶
It calculates the circle area
func CosineSquare ¶ added in v0.15.0
It calculates cosine^2 of the angle in degrees
func GeometricMean ¶ added in v0.19.0
Calculates the geometric mean of the user given values.
Example:
func main() { mathem.GeometricMean(1,2,3,4) // (1*2*3*4)^(1/4) == 2.213 }
func HarmonicMean ¶ added in v0.19.0
Calculates the Harmonic mean of the user given values.
Example:
func main() { mathem.HarmonicMean(1,2,3,4) // [4/(1/1 + 1/2 + 1/3 + 1/4)] == 1.92 }
func ProductOfSequence ¶ added in v0.16.0
func ProductOfSequence(startingValue, endingValue int, function func(value int) float64) (product float64)
ProductOfSequence function will calculate the user defined function from the starting to the ending integer value.
Each output will be multiplied to the following one and then store into the resulting product that will be returned.
Example:
import "github.com/Gabri432/gophysics/mathem"
func main() { var squareFunction = func(value int) float64 { return float64(value*value) //n*n } fmt.Println(mathem.ProductOfSequence(1, 3, squareFunction)) // [1*1] * [2*2] * [3*3] = 1 * 4 * 9 = 36 }
func SineSquare ¶ added in v0.15.0
It calculates sine^2 of the angle in degrees
func SphereVolume ¶
It calculates sphere volume
func StandardDeviation ¶ added in v0.17.0
StandardDeviation is the square root of the Variance.
Example:
func main() { fmt.Println(mathem.StandardDeviation(2, 4, 4, 4, 5, 5, 7, 9)) // returns 2 // STEP 1: Arithmetic mean = 5; // STEP 2: Sum of the square deviations = // = [(2-5)^2 + (4-5)^2 + (4-5)^2 + (4-5)^2 + (5-5)^2 + (5-5)^2 + (7-5)^2 + (9-5)^2] = 40; // STEP 3: Mean of those values = [(9 + 1 + 1 + 1 + 0 + 0 + 4 + 16) / 8] == 4; // STEP 4: Square Root of Variance = 2; }
func Summatory ¶ added in v0.16.0
Summatory function will calculate the user defined function from the starting to the ending integer value.
Each output will be added to the following one and then store into the resulting sum that will be returned.
Example:
import "github.com/Gabri432/gophysics/mathem"
func main() { var oddNumberFunction = func(value int) float64 { return float64(2*value+1) //2n+1 } fmt.Println(mathem.Summatory(1, 3, oddNumberFunction)) // [2*(1)+1] + [2*(2)+1] + [2*(3)+1] = 3 + 5 + 7 = 15 }
func Variance ¶ added in v0.17.0
Variance is the ratio between the square deviations of each value from the mean and the number of values.
Example:
func main() { fmt.Println(mathem.Variance(2, 4, 4, 4, 5, 5, 7, 9)) // returns 4 // STEP 1: Arithmetic mean = 5; // STEP 2: Sum of the square deviations = // = [(2-5)^2 + (4-5)^2 + (4-5)^2 + (4-5)^2 + (5-5)^2 + (5-5)^2 + (7-5)^2 + (9-5)^2] = 40; // STEP 3: Mean of those values = [(9 + 1 + 1 + 1 + 0 + 0 + 4 + 16) / 8] == 4 }
Types ¶
This section is empty.