【问题标题】:Does C++ STL, Eigen or Boost have a inverse hyperbolic secant (asech) function?C++ STL、Eigen 或 Boost 是否具有反双曲正割 (asech) 函数?
【发布时间】:2021-08-21 00:15:30
【问题描述】:

我一直在搜索搜索结果,但我似乎找不到任何关于此功能是否存在于其中的任何一个。我很确定它在 C++ 标准库中不存在。

但是,对于 boost,我看到了对 nt2::asech 的引用,但我不知道这是否是 Boost 的一些第三方扩展或已弃用或什么。

我被 C++、Eigen 和 Boost 困住了,无法为此获得另一个库。

作为旁注,我认为 asech = 1/sech 和 sech = 1/cosh。因此 asech = cosh。但是,这在 MATLAB 测试中不起作用。

【问题讨论】:

  • Wolfram 的inverse hyperbolic secant 提供了一个公式。
  • 尽管像反正弦这样的东西是notated as sin⁻¹,但这并不意味着与倒数相同。反双曲正割也是如此。
  • 您是否考虑过联系 C++ 标准委员会以包含该功能(如果未包含)? C++ 标准委员会的 Walter Brown 会考虑将数学函数放入 C++ 库中,但他可能已经退休了。
  • 在我看来,自己实现似乎并不难。你有什么理由不能这样做?还是我错过了一点?
  • 维基百科还列出了双曲逆的显式公式:en.wikipedia.org/wiki/…——因为这些实现起来非常简单,可能没有人愿意为它们提供库函数。

标签: c++ boost eigen


【解决方案1】:
    //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;
   }

        

 

【讨论】:

    猜你喜欢
    • 2013-03-10
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 2020-06-09
    • 1970-01-01
    相关资源
    最近更新 更多