Home > Backend Development > C++ > C++ program to find hyperbolic arc tangent with given value

C++ program to find hyperbolic arc tangent with given value

PHPz
Release: 2023-09-01 08:13:11
forward
704 people have browsed it

C++ program to find hyperbolic arc tangent with given value

Use hyperbolas instead of circles to define hyperbolic functions. It returns the ratio parameter of the hyperbolic tangent function based on the supplied angle in radians. But quite the opposite. To calculate angles from hyperbolic tangent values, you need to use inverse hyperbolic trigonometric functions (such as the hyperbolic inverse tangent operation).

This article demonstrates how to use the C hyperbolic arctangent (atanh) function to determine an angle from the hyperbolic tangent value in radians. The hyperbolic arctangent operation has the following formula -

$$\mathrm{cosh^{-1}x\:=\:\frac{1}{2}In\left(\frac{1\: \:x}{1\:-\:x }\right)}, where \:In\: represents \:natural logarithm\:(log_e \: k)$$

atanh() function

You can use the atanh() function to calculate angles based on hyperbolic tangent values. This function is part of the C standard library. You need to import the cmath library before using this function. When the hyperbolic tangent value is provided, this procedure provides the angle in radians. The following uses simple syntax -

grammar

#include  − cmath >
atanh( −hyperbolic tangent value> )
Copy after login

The input range of this function is [-1 to 1] (inclusive). If the input exceeds this range, a domain error is raised.

algorithm

  • Take the superbolic tangent value x as input
  • Use atanh(x) to calculate tanh−1(x)
  • Return results.

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;
}
Copy after login

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)
Copy after login

The atanh() method receives the value of the hyperbolic tangent and returns the angle in radian format. We convert this output from radians to degrees using the formula below.

$$\mathrm{\theta_{deg}\:=\:\theta_{rad}\:\times\frac{180}{\pi}}$$

in conclusion

We use the hyperbolic tangent value to perform the inverse hyperbolic operation, using the atanh() function in the cmath library. Based on the input value of hyperbolic tangent, this function returns the desired angle in radians. The input range is -1 to 1. A domain error is raised when the input value is out of range. In early C and C iterations, the return type was double; in subsequent C iterations, overloaded forms of float and long-double were also used. When an integer value is provided as a parameter, the atanh() method will be used after converting the input parameter to double type.

The above is the detailed content of C++ program to find hyperbolic arc tangent with given value. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template