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

双曲反正切在不同角度的值
atanh(0) = 0
atanh(30) = NaN
atanh(45) = NaN
atanh(60) = NaN
atanh(90) = NaN
算法
步骤1 - 声明变量以存储float32类型的守护值和答案。
步骤2 - 初始化变量的值。
步骤3 - 调用双曲反正切函数并传递值。
步骤4 - 打印结果。
示例
在这个例子中,我们将编写一个Go程序,在这个程序中我们将导入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 Tangent of a given value in the Golang programming language using a math package.")
// initializing the value of the variable value
value = 0.5
// finding Hyperbolic Arc Tangent for the given value
answer = math.Atanh(value)
// printing the result
fmt.Println("The Hyperbolic Arc Tangent value with the value of", value, "is", answer)
}
输出
Program to find the Hyperbolic Arc Tangent of a given value in the Golang programming language using a math package. The Hyperbolic Arc Tangent value with the value of 0.5 is 0.5493061443340548
算法
步骤1 - 声明变量以存储float32类型的守护值和答案。
步骤2 - 初始化变量的值。
步骤3 - 调用我们定义的双曲反正切函数并将值作为参数传递。
步骤4 - 打印结果。
示例
在这个例子中,我们将编写一个Go程序,在这个程序中我们将导入math包,在一个单独的函数中调用双曲反正切函数,然后在主函数中调用该函数。
package main
import
(
"fmt"
"math"
)
type of float64
func HyperbolicArcTangent(angle float64) float64 {
// returning the Hyperbolic Arc Tangent of the angle
return math.Atanh(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 Tangent of a given value in the Golang programming language using a separate function in the same program.")
// initializing the value of the value
value = 0.5
// finding Hyperbolic Arc Tangent for the given value in a separate function
answer = HyperbolicArcTangent(value)
// printing the result
fmt.Println("The Hyperbolic Arc Tangent value with the value of", value, "is", answer)
}
输出
Program to find the Hyperbolic Arc Tangent of a given value in the Golang programming language using a separate function in the same program. The Hyperbolic Arc Tangent value with the value of 0.5 is 0.5493061443340548
结论
这是两种使用math包中的函数并将值作为参数传递来查找双曲反正切的方法。第二种方法将为程序提供抽象。要了解更多关于Go的信息,您可以浏览这些教程。
广告
数据结构
网络
关系数据库管理系统(RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP