Golang 如何找到给定弧度值的双曲正弦
在本教程中,我们将学习如何在Golang编程语言中找到一个给定弧度值的双曲正弦。Golang语言有许多带有预定义功能的包,开发者可以使用这些包而无需编写完整的逻辑。
为了执行数学运算和逻辑,我们在Golang中有一个数学包。我们将只使用这个包来寻找一个给定弧度值的双曲正弦。我们还将看到如何导入这个包,以及如何通过编写Golang代码来调用这个包中的一个函数。
双曲正弦
定义
双曲正弦是一个类似于三角函数的函数。代数表达式有助于找到包括指数函数(e^x)在内的双曲函数。双曲正弦的公式写在下面,双曲正弦的值是在不同的角度。
语法
Sinhx = (e^x - e^-x) / 2
图表
不同角度下的双曲正弦值
- 正弦(0)=0
-
正弦(30)=5.3432373e+12
-
正弦(45)=1.7467136e+19
-
正弦(60)=5.7100369e+25
-
sinh(90) = 6.1020165e+38
算法
第1步 - 声明变量以存储监护人和答案的float32类型的值。
第2步 --初始化弧度的变量。
第3步–调用双曲正弦函数并传递弧度值。
第4步 – 打印结果。
例子
在这个例子中,我们将写一个Golang程序,其中我们将导入一个 math 包并调用双曲正弦函数。
package main
import (
// fmt package provides the function to print anything
"fmt"
// math package provides multiple functions for different
// mathematical operations
"math"
)
func main() {
// declaring the variables to store the value of radian value and answer
var radianValue, answer float64
fmt.Println("Program to find the hyperbolic sine of a given radian value in the Golang programming language using a math package.")
// initializing the value of radian value
radianValue = 4.5
// finding hyperbolic sine for the given radian value
answer = math.Sinh(radianValue)
// printing the result
fmt.Println("The hyperbolic sine value with the value of radian", radianValue, "is", answer)
}
输出
Program to find the hyperbolic sine of a given radian value in the Golang programming language using a math package.
The hyperbolic sine value with the value of radian 4.5 is 45.003011151991785
算法
第1步 - 声明变量以存储监护人和答案的float32类型的值。
第2步 - 初始化弧度的变量。
第3步 - 调用我们定义的双曲正弦函数,并传递弧度值作为参数。
第4步 – 打印结果。
例子
在这个例子中,我们将写一个Golang程序,其中我们将导入一个 math 包,并在一个单独的函数中调用双曲正弦函数,并调用该函数main。
package main
import (
// fmt package provides the function to print anything
"fmt"
// math package provides multiple functions for different
// mathematical operations
"math"
)
// this is a function with a parameter of float64 type and a return type of float64
func HyperbolicSine(angle float64) float64 {
// returning the Hyperbolic Sine of the angle
return math.Sinh(angle)
}
func main() {
// declaring the variables to store the value of radian value and answer
var radianValue, answer float64
fmt.Println("Program to find the Hyperbolic Sine of a given radian value in the Golang programming language using a separate function in the same program.")
// initializing the value of the radian value
radianValue = 4.5
// finding hypsine for the given radian value in separate function
answer = HyperbolicSine(radianValue)
// printing the result
fmt.Println("The Hyperbolic Sine value with the value of radian", radianValue, "is", answer)
}
输出
Program to find the Hyperbolic Sine of a given radian value in the Golang programming language using a separate function in the same program.
The Hyperbolic Sine value with the value of radian 4.5 is 45.003011151991785
结论
这是两种通过使用数学包中的函数并将弧度值作为参数传递来寻找双曲正弦的方法。第二种方法将在程序中提供抽象性。