如何在 Golang 中查找给定弧度值的双曲正弦?
在本教程中,我们将学习如何在 Golang 编程语言中查找给定弧度值的双曲正弦。Golang 语言拥有许多包含预定义函数的包,开发人员可以使用这些函数而无需编写完整的逻辑。
为了执行数学运算和逻辑,我们在 Golang 中有一个 math 包。我们只使用此包来查找给定弧度值的双曲正弦。我们还将了解如何导入包以及如何通过编写 Golang 代码来调用此包包含的函数。
双曲正弦
定义
双曲正弦是一个类似于三角函数的函数。代数表达式有助于找到包含指数函数 (e^x) 的双曲函数。下面写出了双曲正弦的公式,以及双曲正弦在不同角度下的值。
语法
Sinhx = (e^x - e^-x) / 2
图形

双曲正弦在不同角度下的值
sinh(0) = 0
sinh(30) = 5.3432373e+12
sinh(45) = 1.7467136e+19
sinh(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 包,并在单独的函数中调用双曲正弦函数,并在主函数中调用该函数。
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
结论
这两种方法都是通过使用 math 包中的函数并将弧度值作为参数传递来查找双曲正弦。第二种方法将为程序提供抽象。要了解更多关于 Golang 的信息,您可以浏览这些 教程。
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP