Namespaces
Variants

std:: tanh (std::valarray)

From cppreference.net
헤더 파일에 정의됨 <valarray>
template < class T >
valarray < T > tanh ( const valarray < T > & va ) ;

va 내의 각 요소에 대해 해당 요소 값의 쌍곡탄젠트를 계산합니다.

목차

매개변수

va - 연산을 적용할 값 배열

반환값

va 내 값들의 쌍곡탄젠트를 포함하는 값 배열.

참고 사항

정규화되지 않은 함수 ( tanh )가 계산 수행에 사용됩니다. 해당 함수를 사용할 수 없는 경우, std:: tanh 인수 종속 lookup 에 의해 사용됩니다.

이 함수는 반환 타입이 std::valarray 와 다르게 구현될 수 있습니다. 이 경우, 대체 타입은 다음과 같은 속성을 가집니다:

가능한 구현

template<class T>
valarray<T> tanh(const valarray<T>& va)
{
    valarray<T> other = va;
    for (T& i : other)
        i = tanh(i);
    return other; // 프록시 객체가 반환될 수 있음
}

예제

#include <cmath>
#include <iostream>
#include <valarray>
auto show = [](char const* title, const std::valarray<double>& va)
{
    std::cout << title << " :";
    for (auto x : va)
        std::cout << "  " << std::fixed << x;
    std::cout << '\n';
};
int main()
{
    const std::valarray<double> x = {.0, .1, .2, .3};
    const std::valarray<double> sinh = std::sinh(x);
    const std::valarray<double> cosh = std::cosh(x);
    const std::valarray<double> tanh = std::tanh(x);
    const std::valarray<double> tanh_by_def = sinh / cosh;
    const std::valarray<double> tanh_2x = std::tanh(2.0 * x);
    const std::valarray<double> tanh_2x_by_def = 
        (2.0 * tanh) / (1.0 + std::pow(tanh, 2.0));
    show("x              ", x);
    show("tanh(x)        ", tanh);
    show("tanh(x) (def)  ", tanh_by_def);
    show("tanh(2*x)      ", tanh_2x);
    show("tanh(2*x) (def)", tanh_2x_by_def);
}

출력:

x               :  0.000000  0.100000  0.200000  0.300000
tanh(x)         :  0.000000  0.099668  0.197375  0.291313
tanh(x) (def)   :  0.000000  0.099668  0.197375  0.291313
tanh(2*x)       :  0.000000  0.197375  0.379949  0.537050
tanh(2*x) (def) :  0.000000  0.197375  0.379949  0.537050

참고 항목

valarray의 각 요소에 함수 std::sinh 를 적용합니다
(함수 템플릿)
valarray의 각 요소에 함수 std::cosh 를 적용합니다
(함수 템플릿)
(C++11) (C++11)
쌍곡탄젠트를 계산합니다 ( tanh(x) )
(함수)
복소수의 쌍곡탄젠트를 계산합니다 ( tanh(z) )
(함수 템플릿)