.TH cosh() "" "" "Mathematics Function (libm)"
.PC "Calculate hyperbolic cosine"
.B "#include <math.h>"
\fBdouble cosh(\fIradian\^\fB) double \fIradian\^\fB;\fR
.PP
.B cosh()
calculates the hyperbolic cosine of
.IR radian ,
which is in radian measure.
.SH Example
The following example uses
.B cosh()
to compute the height and time to impact of a falling object.
Assume that an object is acted on both by gravity and by air
resistance propotional to \fIv\fR\u2\d, where
.I v
is its velocity.
When
.I p
is the proptionality constant for the resistance of air,
the object's height after
.I t
seconds is given by the formula
.DM
	y = y0 -1/p*ln(cosh(t*sqrt(p*g)))
.DE
.PP
and its time to reach the ground is given by the formula:
.DM
	t = 1/sqrt(p*g)*log(exp(p*y0)+sqrt(exp(2*p*y0)-1))
.DE
.PP
Assuming that
.DM
	g = 32 ft/s\u2\d
.DE
.PP
the example computes an object's height after
.I t
seconds and the total time in seconds that it will take to reach the ground.
.II "Lal, Sanjay"
It was written by Sanjay Lal (sanjayl@tor.comm.mot.com):
.DM
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
.DE
.DM
main ()
{
	float height, init_height, resistance, time_to_hit, g;
	int i;
	char buffer[50];
.DE
.DM
	g = 32.0;
.DE
.DM
	printf("Enter initial height, in feet: ");
	fflush(stdout);
	init_height = atof(gets(buffer));
.DE
.DM
	resistance = 0.0;
	while (resistance > 0.005 || resistance < 0.001) {
		printf("Enter air resistance (0.001 to 0.005): ");
		fflush(stdout);
		resistance = atof(gets(buffer));
	}
.DE
.DM
	time_to_hit = 1.0/sqrt(resistance*g) *
		log(exp(resistance*init_height) +
		sqrt(exp(2*resistance*init_height)-1));
.DE
.DM
	printf("Initial height: %1.0f\en", init_height);
	printf("Air resistance: %1.3f\en", resistance);
	printf("Time for object to hit the ground: %1.3f seconds\en",
		time_to_hit);
.DE
.DM
	/* countdown to impact */
	for (i = 2; ; i++) {
		height = init_height -
			(1.0/resistance*log(cosh(sqrt(resistance*g)*(double)i)));
.DE
.DM
		if (height < 0) {
			printf("BOOM!\en");
			exit(EXIT_SUCCESS);
		} else
			printf("Height after %i seconds: %1.3f feet\en", i, height );
	}
}
.DE
.SH "See Also"
.Xr "libm," libm
.Xr "cos()" cos
.br
\*(AS, \(sc7.5.3.1
.br
\*(PX Standard, \(sc8.1
.SH Diagnostics
When overflow occurs,
.B cosh()
returns a huge value that has the same sign as the actual result.
