C cosh
In C, cosh returns the hyperbolic cosine of x, equal to (eˣ + e⁻ˣ) / 2. At zero the result is 1.
A simple example
cosh
- Start with 0
- Do this Evaluate hyperbolic cosine
- Result 1
#include <stdio.h>
#include <math.h>
int main(void) {
printf("%.15g\n", (double) (cosh(0.0)));
}
1
Syntax
cosh(offset)
Run these examples in C
Save one example at a time as lesson.c. Use C17 and a Unix-style shell.
cc -std=c17 -Wall -Wextra lesson.c -lm -o lesson
./lessonEstimate the shape of a hanging cable
An engineering class models a freely hanging cable. Evaluate the curve at the sample position so the team can relate the plotted shape or slope to that point on the cable.
#include <math.h>
#include <stdio.h>
int main(void) {
double offset = 0.5;
printf("%.3f\n", cosh(offset));
return 0;
}
1.128
At half a scale length from the centre, the normalized height is about 1.128. Subtract one for the rise above the lowest point.
Plot the bottom of a cable model
A student models a cable using normalized height y = cosh(x). The drawing starts at the centre, where x is zero.
Using 0 gives 1.000 for this measurement.
Plot a point beside the centre
A scale drawing uses a cable whose normalized height follows cosh(x). The designer samples it one scale length from the centre.
Using 1 gives 1.543 for this measurement.
What to watch for
Absolute height depends on the chosen origin and cable scale.