The COSH()
function in SQLite calculates the hyperbolic cosine of a number, which is similar to the regular cosine function, but for hyperbolic geometry.
Syntax
COSH(x)
Where x
is the input value (in radians) for which you want to compute the hyperbolic cosine.
Hyperbolic Cosine Formula
The hyperbolic cosine of a number x
is given by the formula:
cosh(x) = (e^x + e^(-x)) / 2
Where:
e
is Euler’s number, approximately 2.71828.x
is the input value in radians.
Example 1
Here’s a basic example to demonstrate COSH()
:
SELECT COSH(0);
Output:
1.0
The hyperbolic cosine of 0 is 1
because cosh(0) = (e0 + e0) / 2 = (1 + 1) / 2 = 1
.
Example 2
Let’s do an example that uses COSH()
against data in a table:
CREATE TABLE t1 (x REAL);
INSERT INTO t1 (x) VALUES (0), (1), (-1), (2), (-2);
SELECT x, COSH(x) AS hyperbolic_cosine
FROM t1;
Output:
x hyperbolic_cosine
---- -----------------
0.0 1.0
1.0 1.54308063481524
-1.0 1.54308063481524
2.0 3.76219569108363
-2.0 3.76219569108363
Explanation:
COSH(0)
is1
because forx = 0
, the hyperbolic cosine is always1
(as shown in the previous formula).COSH(1)
andCOSH(-1)
give the same result because the hyperbolic cosine function is an even function, meaningcosh(x) = cosh(-x)
.- For larger values of
x
, the hyperbolic cosine increases exponentially due to the contributions of the terms(ex + e-x) / 2
, where the termex
dominates asx
grows, makingcosh(x)
grow exponentially.
Summary
COSH(x)
computes the hyperbolic cosine of the input valuex
in radians.- It uses the formula
cosh(x) = (ex + e-x) / 2
to calculate the hyperbolic cosine ofx
. - The function is useful for calculations in hyperbolic geometry and other fields of mathematics where hyperbolic functions are needed.