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

双曲余弦反函数在不同角度的值
acosh(0) = NaN
acosh(30) = 4.0940666686320855
acosh(45) = 4.499686190671499
acosh(60) = 4.78742229110268
acosh(90) = 5.192925985263684
算法
步骤 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 \value and answer
var value, answer float64
fmt.Println("Program to find the Hyperbolic Arc Cosine of a given value in the Golang programming language using a math package.")
// initializing the value of the variable value
value = 4.5
// finding Hyperbolic Arc Cosine for the given value
answer = math.Acosh(value)
// printing the result
fmt.Println("The Hyperbolic Arc Cosine value with the value of", value, "is", answer)
}
输出
Program to find the Hyperbolic Arc Cosine of a given value in the Golang programming language using a math package. The Hyperbolic Arc Cosine value with the value of 4.5 is 2.1846437916051085
算法
步骤 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"
)
type of float64
func HyperbolicArcCosine(angle float64) float64 {
// returning the Hyperbolic Arc Cosine of the angle
return math.Acosh(angle)
}
func main() {
// declaring the variables to store the value of value and answer
var value, answer float64
fmt.Println("Program to find the Hyperbolic Arc Cosine of a given value in the Golang programming language using a separate function in the same program.")
// initializing the value of the value
value =4.5
// finding Hyperbolic Arc Cosine for the given value in a separate function
answer = HyperbolicArcCosine(value)
// printing the result
fmt.Println("The Hyperbolic Arc Cosine value with the value of", value, "is", answer)
}
输出
Program to find the Hyperbolic Arc Cosine of a given value in the Golang programming language using a separate function in the same program. The Hyperbolic Arc Cosine value with the value of 4.5 is 2.1846437916051085
结论
这两种方法都是使用 math 包中的函数并将值作为参数传递来查找双曲余弦反函数的方法。第二种方法将为程序提供抽象。要了解更多关于 Golang 的信息,您可以探索这些 教程。
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP