Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Math.Cosh() Method in C#
The Math.Cosh() method in C# returns the hyperbolic cosine of a specified angle in radians. The hyperbolic cosine function is defined mathematically as cosh(x) = (e^x + e^(-x)) / 2, where e is Euler's number.
This method is commonly used in mathematical calculations involving hyperbolic functions, engineering applications, and statistical computations.
Syntax
Following is the syntax −
public static double Cosh(double value);
Parameters
value − A
doublerepresenting an angle measured in radians.
Return Value
Returns a double representing the hyperbolic cosine of the specified value. If the value is NaN (Not a Number), the method returns NaN. For positive or negative infinity, it returns positive infinity.
Using Math.Cosh() with Different Values
Example 1: Basic Usage
using System;
public class Demo {
public static void Main() {
double val1 = 0.0;
double val2 = 1.0;
double val3 = 2.0;
Console.WriteLine("cosh(0) = " + Math.Cosh(val1));
Console.WriteLine("cosh(1) = " + Math.Cosh(val2));
Console.WriteLine("cosh(2) = " + Math.Cosh(val3));
}
}
The output of the above code is −
cosh(0) = 1 cosh(1) = 1.54308063481524 cosh(2) = 3.76219569108363
Using Math.Cosh() with Negative Values
Example 2: Negative and Positive Values
using System;
public class Demo {
public static void Main() {
double positiveVal = 1.5;
double negativeVal = -1.5;
Console.WriteLine("cosh(1.5) = " + Math.Cosh(positiveVal));
Console.WriteLine("cosh(-1.5) = " + Math.Cosh(negativeVal));
Console.WriteLine("Are they equal? " + (Math.Cosh(positiveVal) == Math.Cosh(negativeVal)));
}
}
The output of the above code is −
cosh(1.5) = 2.35240961524325 cosh(-1.5) = 2.35240961524325 Are they equal? True
Using Math.Cosh() with Special Values
Example 3: Special Cases
using System;
public class Demo {
public static void Main() {
Console.WriteLine("cosh(NaN) = " + Math.Cosh(double.NaN));
Console.WriteLine("cosh(+?) = " + Math.Cosh(double.PositiveInfinity));
Console.WriteLine("cosh(-?) = " + Math.Cosh(double.NegativeInfinity));
Console.WriteLine("cosh(0) = " + Math.Cosh(0.0));
}
}
The output of the above code is −
cosh(NaN) = NaN cosh(+?) = ? cosh(-?) = ? cosh(0) = 1
Key Properties
| Property | Description | Example |
|---|---|---|
| Even Function | cosh(x) = cosh(-x) | cosh(2) = cosh(-2) |
| Minimum Value | cosh(0) = 1 (minimum point) | Always ? 1 |
| Range | [1, +?) | Never returns values < 1 |
Conclusion
The Math.Cosh() method calculates the hyperbolic cosine of a given angle in radians. It's an even function that always returns values ? 1, with its minimum value of 1 occurring at cosh(0). This method is essential for mathematical computations involving hyperbolic functions.
