Home  >  Article  >  Backend Development  >  C++ program to find the hyperbolic inverse cosine function taking a given value as an argument

C++ program to find the hyperbolic inverse cosine function taking a given value as an argument

WBOY
WBOYforward
2023-09-04 09:45:06497browse

C++ program to find the hyperbolic inverse cosine function taking a given value as an argument

Similar to ordinary trigonometric functions, hyperbolic functions are defined using hyperbolas instead of circles. From the specified angle in radians, it returns the ratio parameter in the hyperbolic cosine function. But in other words, it's the opposite. Inverse hyperbolic trigonometric operations (such as inverse hyperbolic cosine operations) are required to determine the angle corresponding to the hyperbolic cosine value.

Calculate angles in radians using hyperbolic cosine values. This tutorial will show you how to use the C hyperbolic inverse cosine (acosh) function. The formula for hyperbolic inverse cosine operation is as follows -

$$\mathrm{cosh^{-1}x\:=\:In(x\: \:\sqrt{x^2\:-\:1})}, where \:In\: is \:Natural logarithm\:(log_e \: k)$$

acosh() function

Using the acosh() function, the angle can be determined based on the hyperbolic cosine value. The C standard library contains this function. Before using this feature, the cmath library must be imported. This method accepts a hyperbolic cosine value as input and returns the angle in radians. The following uses simple syntax -

grammar

#include < cmath >
acosh( <hyperbolic cosine value> )

The input range of this function is 1 and above. If the input is negative, a domain error is raised. It returns a number in the range [0, ∞] (both inclusive).

algorithm

  • Take the hyperbolic cosine value x as input
  • Use acosh(x) to calculate cosh−1(x)
  • Return results.

Example

#include <iostream>
#include <cmath>
using namespace std;

float solve( float x ) {
   float answer;
   answer = acosh( x );
   return answer;
}

int main()
{
   float angle, ang_deg;
   angle = solve( 2.50918 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given hyperbolic cosine value 2.50918 is: " << angle << " = " << ang_deg << " (in degrees)" << endl;

   angle = solve( 11.5919 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given hyperbolic cosine value 11.5919 is: " << angle << " = " << ang_deg << " (in degrees)" << endl;

   angle = solve( 1.32461 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given hyperbolic cosine value 1.32461 is: " << angle << " = " << ang_deg << " (in degrees)" << endl;

   angle = solve( 1.60028 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given hyperbolic cosine value 1.60028 is: " << angle << " = " << ang_deg << " (in degrees)" << endl;
}

Output

The angle (in radian) for given hyperbolic cosine value 2.50918 is: 1.5708 = 90.0001 (in degrees)
The angle (in radian) for given hyperbolic cosine value 11.5919 is: 3.14159 = 180 (in degrees)
The angle (in radian) for given hyperbolic cosine value 1.32461 is: 0.785399 = 45.0001 (in degrees)
The angle (in radian) for given hyperbolic cosine value 1.60028 is: 1.04719 = 59.9997 (in degrees)

Pass the hyperbolic cosine value to the acosh() method, which returns the angle in radians format. Using the algorithm below, we convert this output from radians to degrees.

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

in conclusion

We use the acosh() function from the cmath package to perform inverse hyperbolic operations using hyperbolic cosine values. This function outputs the desired angle in radians based on the input value of hyperbolic cosine. The range returned is 0 to positive infinity. When the input value is less than 1, a domain error is raised. The return type in early iterations of C and C is double; subsequent iterations of C also use overloaded forms of float and long-double. When an integer value is provided as an argument, the acosh() function is called after converting the input argument to type double.

The above is the detailed content of C++ program to find the hyperbolic inverse cosine function taking a given value as an argument. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete