PHP cosh() Function


Definition and Usage

The cosh() function returns the hyperbolic cosine ratio of given angle in radians. In trigonometry, hyperbolic cosine ratio is defined as .

cosh(x) = (ex – e-x))/2

This function returns a float value .

Syntax

cosh ( float $arg ) : float

Parameters

Sr.NoParameter & Description
1arg
A floating point value that represents angle in radians

Return Values

PHP cosh() function returns hyperbolic cosine ratio of given parameter.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

 Live Demo

Following example calculates cosh(pi/2) and returns 2.5091784786581 which is also the result of formula (ex + e-x))/2 −

<?php
   $arg=M_PI_2;
   $val=(exp($arg)+exp(-$arg))/2;
   $res=cosh($arg);
   echo "cosh(M_PI_2) = " . $val. "
";    echo "using formula = " . $res . "
"; ?>

Output

This will produce following result −

cosh(M_PI_2) = 2.5091784786581
using formula = 2.5091784786581

Example

 Live Demo

Following example uses deg2rad() function to convert degrees to radians and then uses cosh(60). Result is 1.6002868577024 −

<?php
   $arg=deg2rad(60);
   $val=cosh($arg);
   echo "cosh(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

cosh(1.0471975511966) = 1.6002868577024

Example

 Live Demo

Let's check find out cosh(0). It returns 1 −

<?php
   $arg=0;
   $val=cosh($arg);
   echo "cosh(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

cosh(0) = 1

Example

 Live Demo

Following example computes cosh(pi)

<?php
   $arg=M_PI;
   $val=cosh($arg);
   echo "cosh(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

cosh(3.1415926535898) = 11.591953275522

Updated on: 29-Jun-2020

119 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements