- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Haskell Program to find the hyperbolic arctangent of the given value
This tutorial will help us in finding hyperbolic arctangent of the given value. The hyperbolic arctangent, also known as the inverse hyperbolic tangent, is the inverse function of the hyperbolic tangent. It is denoted by atanh (or arctanh) and can be defined as atanh(x) = (ln(1+x) - ln(1-x)) / 2
Syntax
atanh(angle)
Here, atanh() is a function and value is passed as parameter to compute the hyperbolic arctangent of the value passed. It returns a value in the range of (-infinity, infinity). In Haskell, the atanh() function is a part of the Floating class, which is a subclass of the Real class. It is used to calculate the inverse hyperbolic tangent of a value, which is the value whose hyperbolic tangent is equal to the given value.
Method 1: Using log() Function
In this method, the function uses the natural logarithm function (log) and the square root function (sqrt) to calculate the hyperbolic arctangent of the input value and result is computed once the function is being called.
Algorithm
Step 1 − “Data.Complex” module is imported to work over the log function.
Step 2 − Program execution will be started from main function. The main() function has whole control of the program.
Step 3 − A variable named, “value” is being initialized. Initially, it will have the garbage value. Then, a constant value is being assigned to it. This value is assigned to the variable “value” by using the assignment operator.
Step 4 − The hyperbolic arctangent function, atanh() is called. If we are not using cmath library then, we have to define the atanh() function. In order to compute the hyperbolic arctangent of the value passed, the atanh() function is defined using log and sqrt function as atanh x = log ((1 + x) / (1 - x)) / 2.
Step 5 − “value” variable that contains the value, is passed as parameter to the atanh() function.
Step 6 − The result is assigned to the “result” variable after atanh() function computes the final resultant value and final output is displayed by printing the result value.
Example
In this example, we are going to see that how we can find the hyperbolic arctangent of the value passed using log() function
import Data.Complex atanh :: Double -> Double atanh x = log ((1 + x) / (1 - x)) / 2 main :: IO() main = do let value = 0.5 let result = Prelude.atanh value putStrLn ("The hyperbolic arctangent of " ++ show value ++ " is " ++ show result)
Output
The hyperbolic arctangent of 0.5 is 0.5493061443340549
Method 2: Using atanh() Function
In this approach, the hyperbolic arctangent of a given value is computed directly by calling atanh() function. The atanh() function has its definition included in cmath library. Thus, we can directly call this function and pass value as parameter to it. And then resultant hyperbolic arctangent is displayed on the screen.
Algorithm
Step 1 − The “Data.Complex” module is imported.
Step 2 − Program execution will be started from main function. The main() function has whole control of the program.
Step 3 − A variable named, “value” is being initialized. Initially, it will have the garbage value. Then, a constant value is being assigned to it. This value is assigned to the variable “value” by using the assignment operator.
Step 4 − The hyperbolic arctangent function atanh() that already contains its function definition to compute the hyperbolic arctangent in cmath library, is directly called.
Step 5 − “value” variable that contains the value, is passed as parameter to the atanh() function, by simply writing variable name along with the function called.
Step 6 − The result is assigned to the “result” variable after atanh() function computes the final resultant value and final output is displayed by printing the result value. . To print the result, we can use ‘putStrLn’ as putStrLn ("The hyperbolic arctangent of " ++ show value ++ " is " ++ show result). Instead, we can also use print (result).
Example
In this example, we are going to see how we can find the hyperbolic arctangent of the value passed using atanh() function
import Data.Complex main :: IO () main = do let value = 0.5 let result = Prelude.atanh value putStrLn ("The hyperbolic arctangent of " ++ show value ++ " is " ++ show result)
Output
The hyperbolic arctangent of 0.5 is 0.5493061443340549
Conclusion
The hyperbolic arctangent value for the given value in Haskell can be calculated by using the atanh() function. The hyperbolic arctangent, atanh() function is a built-in function in Haskell, whose definition is already available in cmath library. Otherwise,if we would not use cmath library then we can also define the function definition for hyperbolic arctangent function using log function.
The hyperbolic arctangent function is useful in areas such as physics, engineering, and computer science, where it is used in the study of hyperbolic functions and their properties.