JavaScript Math cosh()方法

下面是Math cosh()方法的示例。

null
  • 例子:

Javascript

<script>
// Printing hyperbolic cosine of some numbers
// taken as parameter of Math.cosh() method.
document.write(Math.cosh(0) + "<br>" );
document.write(Math.cosh(1) + "<br>" );
document.write(Math.cosh(0) + "<br>" );
document.write(Math.cosh(22) + "<br>" );
document.write(Math.cosh(-2) + "<br>" );
document.write(Math.cosh(4));
</script>


  • 输出:
 1 1.5430806348152437 1 1792456423.065796 3.7621956910836314 27.308232836016487

数学cosh() 方法用于计算数字的双曲余弦值。

语法:

Math.cosh(x)

参数: 该方法接受单参数,如上所述,如下所述:

  • x: 此参数包含一个数字,双曲余弦的值将被计算。 返回: 它返回数字的双曲余弦的计算值。 下面的示例演示了JavaScript中的Math cosh()方法:
  • 例1: 这里计算任意数的双曲余弦的公式是: E 是一个数学常数,其近似值等于 2.718 .

 frac{e^{p} + e^{-p}}{2} = frac{e^{0} + e^{-0}}{2}=frac{1+1}{2}= 1

Input : Math.cosh(0)Output : 1
  • 例2: 同样,只要用所需的数字替换p,就可以计算任意数字的双曲余弦。这里和上面的计算一样,当我们用12代替p时,值变成如上所示的输出。
Input : Math.cosh(12)Output : 81377.39571257407

以上方法的更多代码如下:

项目1: 错误和异常,这是一种错误情况,因为复数不能作为方法的参数,只有整数值可以作为参数。

Javascript

<script>
// Complex number can not be calculated as the
// hyperbolic cosine.
document.write(Math.cosh(1 + 2i));
</script>


输出:

Error: Invalid or unexpected token

项目2: 除了整数,没有任何东西被接受为方法的参数,这就是为什么这里字符串作为参数给出NaN,即,不是一个数字。

Javascript

<script>
// Any string value as the parameter of the method
// gives NaN i.e, not a number
// because only number can be used as the parameters.
document.write(Math.cosh( "geeksforgeeks" ) + "<br>" );
document.write(Math.cosh( "gfg" ));
</script>


输出:

NaNNaN

方案3: 它的实际应用是,每当我们需要求一个数字的双曲余弦值时,我们都会借助数学。JavaScript中的cosh()方法。

Javascript

<script>
// Printing hyperbolic cosine of some numbers
// from 0 to 9 taken as parameter
for (i = 0; i < 10; i++) {
document.write(Math.cosh(i) + "<br>" );
}
</script>


输出:

11.54308063481524373.762195691083631410.06766199577776527.30823283601648774.20994852478785201.7156361224559548.3170351552121490.4791612521784051.5420254925943

支持的浏览器:

  • 谷歌浏览器38.0
  • Internet Explorer 12.0
  • 火狐25.0
  • 歌剧25.0
  • Safari 8.0
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享