C library - cosh() function



The C library cosh() function of type double accepts the parameter(x) that returns the hyperbolic cosine of x. Programatically, it is used to represent the angle of geometrical figure.

The hyperbolic cosine is used in the engineering physics as it appears in the solution of the heat equation in a rod when temperature is molded.

Syntax

Following is the syntax of the C library function cosh()

double cosh(double x)

Parameters

This function accepts only a single parameters.

  • x − This is the floating point value.

Return Value

This function returns hyperbolic cosine of x.

Example 1

Following is the basic C library program that illustrates the usage of cosh() function.

#include <stdio.h>
#include <math.h>

int main () {
   double x;

   x = 0.5;
   printf("The hyperbolic cosine of %lf is %lf\n", x, cosh(x));

   x = 1.0;
   printf("The hyperbolic cosine of %lf is %lf\n", x, cosh(x));

   x = 1.5;
   printf("The hyperbolic cosine of %lf is %lf\n", x, cosh(x));

   return(0);
}

Output

The above code produces the following result −

The hyperbolic cosine of 0.500000 is 1.127626
The hyperbolic cosine of 1.000000 is 1.543081
The hyperbolic cosine of 1.500000 is 2.352410

Example 2

We use cosh() into a for loop which generates the table of hyperbolic cosine values for a range of positive numbers.

#include <stdio.h>
#include <math.h>

int main() {
   printf("Table of Hyperbolic Cosines:\n");
   for (double x = 0.0; x <= 1.5; x += 0.5) {
       double res = cosh(x);
       printf("cosh(%.2lf) = %.6lf\n", x, res);
   }
   return 0;
}

Output

On execution of above code, we get the following result −

Table of Hyperbolic Cosines:
cosh(0.00) = 1.000000
cosh(0.50) = 1.127626
cosh(1.00) = 1.543081
cosh(1.50) = 2.352410

Example 3

Below the program uses cosh() function to find the hyperbolic cosine of a real number.

#include <stdio.h>
#include <math.h>

int main() {
   double x = 0.5;
   double result = cosh(x);
   printf("Hyperbolic cosine of %.2lf (in radians) = %.6lf\n", x, result);
   return 0;
}

Output

After executing the code, we get the following result −

Hyperbolic cosine of 0.50 (in radians) = 1.127626
Advertisements