Golang 如何找到给定值的双曲反余弦

Golang 如何找到给定值的双曲反余弦

在本教程中,我们将学习如何在Golang编程语言中找到给定值的双曲反余弦。Golang语言中有许多带有预定义函数的包,开发者可以在不编写完整逻辑的情况下使用。

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

双曲反余弦

定义

双曲反余弦是一种类似于三角函数的函数。双曲反余弦等于三角函数的相似函数。双曲反余弦的公式如下,并且双曲反余弦在不同的角度具有不同的值。

语法

acosh(x) = ln(x + √x^2 - 1)

图表

Golang 如何找到给定值的双曲反余弦

不同角度下的双曲反余弦值

  • 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 - 声明一个变量来存储保护者和浮点型答案的值。

步骤2 - 初始化一个数值变量。

步骤3 - 调用我们定义的双曲反余弦函数,并将数值作为参数传递。

步骤4 - 打印结果。

示例

在这个示例中,我们将编写一个Golang程序,在程序中导入一个 math 包,并在一个单独的函数中调用双曲反余弦函数,并调用该函数main。

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

结论

有两种方法可以通过使用数学包中的函数并将值作为参数传递来找到双曲余弦反函数。第二种方法将在程序中提供抽象性。要了解更多关于Golang的信息,您可以探索这些 教程。

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程