
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Hyperbolic Arctangent of a Given Value in C++
The hyperbola, rather than the circle, is used to define hyperbolic functions. It returns the ratio parameter for the hyperbolic tangent function based on the supplied radian angle. On the contrary, however. To calculate the angle from the hyperbolic-tangent value, inverse hyperbolic trigonometric procedures like the hyperbolic arctangent operation are required.
This article will demonstrate how to utilize the C++ hyperbolic inverse-tangent (atanh) function to determine the angle using the hyperbolic tangent value, in radians. The hyperbolic inverse-tangent operation has the following formula ?
$$\mathrm{cosh^{-1}x\:=\:\frac{1}{2}In\left(\frac{1\:+\:x}{1\:-\:x}\right)},where \:In\: is\: natural\: logarithm\:(log_e \: k)$$
The atanh() function
The angle can be calculated from the hyperbolic tangent value using the atanh() function. This function is a part of the C++ standard library. It is necessary to import the cmath library before using this function. When a hyperbolic tangent value is provided, this procedure provides the angle in radians. The following uses the simple syntax ?
Syntax
#include ? cmath > atanh( ?hyperbolic tangent value> )
The input range for this function is [-1 to 1] (both included). If the input is out of this range, it will raise a domain error.
Algorithm
- Take hyperbolic tangent value x as input
- Use atanh( x ) to calculate the tanh?1(x)
- Return result.
Example
#include <iostream> #include <cmath> using namespace std; float solve( float x ) { float answer; answer = atanh( x ); return answer; } int main() { float angle, ang_deg; angle = solve( 0.9171521 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given hyperbolic tangent value 0.9171521 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( 0.996272 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given hyperbolic tangent value 0.996272 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( 0.655794 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given hyperbolic tangent value 0.655794 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( -0.655794 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given hyperbolic tangent value - 0.655794 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; }
Output
The angle (in radian) for given hyperbolic tangent value 0.9171521 is: 1.57079 = 90 (in degrees) The angle (in radian) for given hyperbolic tangent value 0.996272 is: 3.14159 = 180 (in degrees) The angle (in radian) for given hyperbolic tangent value 0.655794 is: 0.785398 = 45 (in degrees)The angle (in radian) for given hyperbolic tangent value - 0.655794 is: -0.785398 = -45 (in degrees)
The atanh() method receives the value of the hyperbolic tangent and returns the angle in radian format. We converted this output from radians to degrees using the formula below.
$$\mathrm{\theta_{deg}\:=\:\theta_{rad}\:\times\frac{180}{\pi}}$$
Conclusion
We use the hyperbolic tangent value to conduct the inverse hyperbolic operation using the atanh() function from the cmath library. Based on the input value of the hyperbolic tangent, this function returns the desired angle in radians. The input's range is from -1 to +1. When the input value is outside of the range, the domain error is raised. In early iterations of C and C++, the return type was double; in later iterations of C++, the overloaded form for float and long-double was also used. The atanh() method will be used after casting the input parameter into the double type when an integer value is provided as an argument.