如何在Golang中查找给定值的双曲反正弦?


在本教程中,我们将学习如何在Golang编程语言中查找给定值的双曲反正弦。Golang语言有很多包,其中包含预定义函数,开发者可以使用这些函数而无需编写完整的逻辑。

为了执行数学运算和逻辑,Golang中有一个math包。我们只使用这个包来查找给定值的双曲反正弦。我们还将看到如何导入包,以及如何通过编写Golang代码来调用该包包含的函数。

双曲反正弦

定义

双曲反正弦是一个类似于三角函数的函数。双曲反正弦等于三角函数的类似物。双曲反正弦的公式如下所示,双曲反正弦在不同角度的值也不同。

语法

asinh(x) = ln(x + √x^2 + 1) 

图形


双曲反正弦在不同角度的值

  • asinh(0) = 0

  • asinh(30) = 4.094622224331

  • asinh(45) = 4.499933104264

  • asinh(60) = 4.787561179994

  • asinh(90) = 5.192987713659

算法

步骤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 sine 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 sine for the given value
   answer = math.Asinh(value)
   
   // printing the result
   fmt.Println("The Hyperbolic Arc sine value with the value of", value, "is", answer)
}

输出

Program to find the Hyperbolic Arc sine of a given value in the Golang programming language using a math package.
The Hyperbolic Arc sine value with the value of 4.5 is 2.209347708615334 

算法

步骤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 HyperbolicArcSine(angle float64) float64 {
   
   // returning the Hyperbolic Arc Sine of the angle
   return math.Asinh(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 Sine of a given value in the Golang programming language using a separate function in the same program.")
   
   // initializing the value of the value
   value = 1
   
   // finding Hyperbolic Arc sine for the given value in a separate function
   answer = HyperbolicArcSine(value)
   
   // printing the result
   fmt.Println("The Hyperbolic Arc Sine value with the value of", value, "is", answer)
} 

输出

Program to find the Hyperbolic Arc Sine of a given value in the Golang programming language using a separate function in the same program.
The Hyperbolic Arc Sine value with the value of 1 is 0.8813735870195432

结论

这两种方法都是使用math包中的函数并将值作为参数传递来查找双曲反正弦的方法。第二种方法将为程序提供抽象。要了解更多关于Golang的信息,您可以浏览这些教程。

更新于:2022年11月29日

100 次浏览

开启你的职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.