Namespaces
Variants

std:: cosh (std::valarray)

From cppreference.net
ヘッダーで定義 <valarray>
template < class T >
valarray < T > cosh ( const valarray < T > & va ) ;

va 内の各要素について、その値の双曲線余弦を計算します。

目次

パラメータ

va - 操作を適用する値配列

戻り値

va 内の値の双曲線余弦を含む値配列。

注記

修飾されていない関数 ( cosh ) が計算の実行に使用されます。該当する関数が利用できない場合、 std:: cosh argument-dependent lookup によって使用されます。

この関数は、戻り値の型が std::valarray と異なる型で実装される場合があります。この場合、置換型は以下の特性を持ちます:

実装例

template<class T>
valarray<T> cosh(const valarray<T>& va)
{
    valarray<T> other = va;
    for (T& i : other)
        i = cosh(i);
    return other; // プロキシオブジェクトが返される可能性があります
}

#include <cmath>
#include <iomanip>
#include <iostream>
#include <valarray>
void show(const char* title, const std::valarray<float>& data)
{
    const int w{9};
    std::cout << std::setw(w) << title << " | ";
    for (float x : data)
        std::cout << std::setw(w) << x << " | ";
    std::cout << '\n';
}
int main()
{
    const std::valarray<float> x{.1, .2, .3, .4};
    const auto sinh = std::sinh(x);
    const auto cosh = std::cosh(x);
    const auto z = (cosh * cosh) - (sinh * sinh);
    show("x", x);
    show("sinh(x)", sinh);
    show("cosh(x)", cosh);
    show("z", z);
}

出力:

        x |       0.1 |       0.2 |       0.3 |       0.4 | 
  sinh(x) |  0.100167 |  0.201336 |   0.30452 |  0.410752 | 
  cosh(x) |     1.005 |   1.02007 |   1.04534 |   1.08107 | 
        z |         1 |         1 |         1 |         1 |

関連項目

valarrayの各要素に関数 std::sinh を適用する
(関数テンプレート)
valarrayの各要素に関数 std::tanh を適用する
(関数テンプレート)
(C++11) (C++11)
双曲線余弦を計算する ( cosh(x) )
(関数)
複素数の双曲線余弦を計算する ( cosh(z) )
(関数テンプレート)