Golang 如何找到给定弧度值的双曲余弦函数

Golang 如何找到给定弧度值的双曲余弦函数

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

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

双曲余弦函数

定义

双曲余弦函数类似于三角函数。代数表达式有助于找到包括指数函数(e^x)的双曲函数。双曲余弦函数的公式如下,并且在不同的角度下具有不同的值。

语法

Coshx = (e^x + e^-x) / 2

Golang 如何找到给定弧度值的双曲余弦函数

不同角度下的双曲余弦值

  • 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 - 打印结果。

示例

在此示例中,我们将编写一个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 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 – 声明一个变量,用于存储保护者和浮点32类型的答案值。

步骤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

结论

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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程