如何在 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 的資訊,您可以探索這些 教程。

更新於: 2022年11月29日

104 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告