Does C++ STL, Eigen or Boost have a inverse hyperbolic secant (asech) function?

Viewed 143

I've been pouring over search results, but I can't seem to find anything on if this function exists in any of them. I'm pretty sure it does not exist in the C++ standard library.

However, for boost I saw references to nt2::asech but I can't tell if that's some third-party extension to Boost or deprecated or what.

I'm stuck with C++, Eigen and Boost, can't get another library in there for this.

As a sidenote, I thought that asech = 1/sech, and sech = 1/cosh. So therefore asech = cosh. However, that does not work in testing from MATLAB.

1 Answers
    //in case of normal trigonometric functions
    // the relation is reverse i.e., sin(x)=(1/cosec(x))
    // but in case of inverse trigonometric functions
    // the relation changes to asin(x)=acosec(1/x)
    // now if we apply the same idea to hyperbolic functions as well
    // then we find that asinh(x)=acosech(1/x) and asech(x)=acosh(1/x)
    // also each hyperbolic functions have their own domain and ranges
    // and in your case(asech(x)) the domain is (0,1] (all values between      
    // zero(0 not included) to 1(1 included)
    // therefore your x inside acosh(1/x) should be between (0,1]
    // and all the outputs are going to be positive [0,inf)

    #include<boost/math/special_functions/acosh.hpp>
    #include<iostream>
    #include<vector>
    int main()
    {
       std::vector<double> v={1,0.832,0.213,0.9,0.1};
       for (auto x:v)
       {
          std::cout<<"The value of arc sec x for  " << x<< "is "<<acosh(1/x)<<" "<<std::endl;
       }
       return 0;
   }

        

 
Related