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

双曲余弦在不同角度的值
cosh(0) = 1
cosh(30) = 5.3432373e+12
cosh(45) = 1.7467136e+19
cosh(60) = 5.7100369e+25
cosh(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 Cosine 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 Cosine for the given radian value
answer = math.Cosh(radianValue)
// printing the result
fmt.Println("The hyperbolic Cosine value with the value of radian", radianValue, "is", answer)
}
输出
Program to find the hyperbolic Cosine of a given radian value in the Golang programming language using a math package. The hyperbolic Cosine value with the value of radian 4.5 is 45.014120148530026
算法
步骤 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 HyperbolicCosine(angle float64) float64 {
// returning the Hyperbolic Cosine of the angle
return math.Cosh(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 Cosine 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 hyperbolic Cosine for the given radian value in separate function
answer = HyperbolicCosine(radianValue)
// printing the result
fmt.Println("The Hyperbolic Cosine value with the value of radian", radianValue, "is", answer)
}
输出
Program to find the Hyperbolic Cosine of a given radian value in the Golang programming language using a separate function in the same program. The Hyperbolic Cosine value with the value of radian 4.5 is 45.014120148530026
结论
这两种方法都是使用 math 包中的函数并将弧度值作为参数传递来查找双曲余弦。第二种方法将为程序提供抽象。要了解有关 Golang 的更多信息,您可以浏览这些 教程。
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP