C library - sinh() function



The C library sinh() function of type double accept the parameter x to return the value of hyperbolic sine.

This function is useful in the context of complex number calculation particulary when it deals with the imaginary part of complex exponential. We also perform this function to numerical method.

Syntax

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

double sinh(double x)

Parameters

This function takes only a single parameter.

  • x − This is the floating point value.

Return Value

This function returns hyperbolic sine of x.

Example 1

Following is the basic C library program to see the illustration of sinh() function.

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

int main () {
   double x, ret;
   x = 0.5;

   ret = sinh(x);
   printf("The hyperbolic sine of %lf is %lf degrees", x, ret);
   
   return(0);
}

Output

The above code produces the following output −

The hyperbolic sine of 0.500000 is 0.521095 degrees

Example 2

The program operate the task on array of floating point values that passes through loop operation to calculate the hyperbolic sine value.

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

int main() {
    
    double val[] = {11.0, 21.0, 31.0, 41.0}; 
    int num_val = sizeof(val) / sizeof(val[0]);

    printf("Hyperbolic Sine values:\n");
    for (int i = 0; i < num_val; ++i) {
        double res = sinh(val[i]);
        printf("sinh(%.2f) = %.4f\n", val[i], res);
    }

    return 0;
}

Output

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

Hyperbolic Sine values:
sinh(11.00) = 29937.0708
sinh(21.00) = 659407867.2416
sinh(31.00) = 14524424832623.7129
sinh(41.00) = 319921746765027456.0000

Example 3

In this program, we use the trapezium rule that performs numerical integration to calculate the hyperbolic sine value.

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

// Function to calculate the hyperbolic sine
double sinh(double x) {
   return (exp(x) - exp(-x)) / 2.0;
}

// Numerical integration using the trapezium rule
double integrate_sinh(double a, double b, int num_intervals) {
   double h = (b - a) / num_intervals;
   double integral = 0.0;

   for (int i = 0; i < num_intervals; ++i) {
       double x0 = a + i * h;
       double x1 = a + (i + 1) * h;
       integral += (sinh(x0) + sinh(x1)) * h / 2.0;
    }

   return integral;
}

int main() {
   // Lower limit of integration
   double a = 0.0; 
   
   // Upper limit of integration
   double b = 2.0; 
   
   // Number of intervals for numerical integration
   int num_intervals = 1000; 

   double result = integrate_sinh(a, b, num_intervals);

   printf("Integral of sinh(x) from %.2lf to %.2lf = %.6lf\n", a, b, result);
   return 0;
}

Output

After executing the code, we get the following result −

Integral of sinh(x) from 0.00 to 2.00 = 2.762197
Advertisements