[35] | 1 | /*! |
---|
| 2 | * \file |
---|
| 3 | * \brief Trigonometric and hyperbolic functions - header file |
---|
| 4 | * \author Tony Ottosson and Adam Piatyszek |
---|
| 5 | * |
---|
| 6 | * ------------------------------------------------------------------------- |
---|
| 7 | * |
---|
| 8 | * IT++ - C++ library of mathematical, signal processing, speech processing, |
---|
| 9 | * and communications classes and functions |
---|
| 10 | * |
---|
| 11 | * Copyright (C) 1995-2007 (see AUTHORS file for a list of contributors) |
---|
| 12 | * |
---|
| 13 | * This program is free software; you can redistribute it and/or modify |
---|
| 14 | * it under the terms of the GNU General Public License as published by |
---|
| 15 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 16 | * (at your option) any later version. |
---|
| 17 | * |
---|
| 18 | * This program is distributed in the hope that it will be useful, |
---|
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 21 | * GNU General Public License for more details. |
---|
| 22 | * |
---|
| 23 | * You should have received a copy of the GNU General Public License |
---|
| 24 | * along with this program; if not, write to the Free Software |
---|
| 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 26 | * |
---|
| 27 | * ------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef TRIG_HYP_H |
---|
| 31 | #define TRIG_HYP_H |
---|
| 32 | |
---|
| 33 | #ifndef _MSC_VER |
---|
| 34 | # include <itpp/config.h> |
---|
| 35 | #else |
---|
| 36 | # include <itpp/config_msvc.h> |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | #include <itpp/base/help_functions.h> |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | //! \addtogroup hypfunc |
---|
| 43 | //!@{ |
---|
| 44 | |
---|
| 45 | #ifndef HAVE_ASINH |
---|
| 46 | //! Arcus sinhyp |
---|
| 47 | inline double asinh(double x) |
---|
| 48 | { |
---|
| 49 | return ((x >= 0) ? log(x + sqrt(x * x + 1)) : -log( -x + sqrt(x * x + 1))); |
---|
| 50 | } |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | #ifndef HAVE_ACOSH |
---|
| 54 | //! Arcus coshyp |
---|
| 55 | inline double acosh(double x) |
---|
| 56 | { |
---|
| 57 | it_error_if(x < 1, "acosh(): Argument must be greater then 1."); |
---|
| 58 | return log(x + sqrt(x * x - 1.0)); |
---|
| 59 | } |
---|
| 60 | #endif |
---|
| 61 | |
---|
| 62 | #ifndef HAVE_ATANH |
---|
| 63 | //! Arcus tanhyp |
---|
| 64 | inline double atanh(double x) |
---|
| 65 | { |
---|
| 66 | it_error_if(fabs(x) >= 1,"atanh(): Argument out of range."); |
---|
| 67 | return 0.5 * log((x + 1) / (x - 1)); |
---|
| 68 | } |
---|
| 69 | #endif |
---|
| 70 | |
---|
| 71 | //!@} |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | namespace itpp { |
---|
| 75 | |
---|
| 76 | //!\addtogroup trifunc |
---|
| 77 | //!@{ |
---|
| 78 | |
---|
| 79 | //! Sinc function: sinc(x) = sin(pi*x)/pi*x |
---|
| 80 | inline double sinc(double x) |
---|
| 81 | { |
---|
| 82 | return ((x == 0) ? 1.0 : sin(itpp::pi * x) / itpp::pi / x); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //! Sine function |
---|
| 86 | inline vec sin(const vec &x) { return apply_function<double>(std::sin, x); } |
---|
| 87 | //! Sine function |
---|
| 88 | inline mat sin(const mat &x) { return apply_function<double>(std::sin, x); } |
---|
| 89 | //! Cosine function |
---|
| 90 | inline vec cos(const vec &x) { return apply_function<double>(std::cos, x); } |
---|
| 91 | //! Cosine function |
---|
| 92 | inline mat cos(const mat &x) { return apply_function<double>(std::cos, x); } |
---|
| 93 | //! Tan function |
---|
| 94 | inline vec tan(const vec &x) { return apply_function<double>(std::tan, x); } |
---|
| 95 | //! Tan function |
---|
| 96 | inline mat tan(const mat &x) { return apply_function<double>(std::tan, x); } |
---|
| 97 | //! Inverse sine function |
---|
| 98 | inline vec asin(const vec &x) { return apply_function<double>(std::asin, x); } |
---|
| 99 | //! Inverse sine function |
---|
| 100 | inline mat asin(const mat &x) { return apply_function<double>(std::asin, x); } |
---|
| 101 | //! Inverse cosine function |
---|
| 102 | inline vec acos(const vec &x) { return apply_function<double>(std::acos, x); } |
---|
| 103 | //! Inverse cosine function |
---|
| 104 | inline mat acos(const mat &x) { return apply_function<double>(std::acos, x); } |
---|
| 105 | //! Inverse tan function |
---|
| 106 | inline vec atan(const vec &x) { return apply_function<double>(std::atan, x); } |
---|
| 107 | //! Inverse tan function |
---|
| 108 | inline mat atan(const mat &x) { return apply_function<double>(std::atan, x); } |
---|
| 109 | //! Sinc function, sin(pi*x)/(pi*x) |
---|
| 110 | inline vec sinc(const vec &x) { return apply_function<double>(sinc, x); } |
---|
| 111 | //! Sinc function, sin(pi*x)/(pi*x) |
---|
| 112 | inline mat sinc(const mat &x) { return apply_function<double>(sinc, x); } |
---|
| 113 | |
---|
| 114 | //!@} |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | //!\addtogroup hypfunc |
---|
| 118 | //!@{ |
---|
| 119 | |
---|
| 120 | //! Sine hyperbolic function |
---|
| 121 | inline vec sinh(const vec &x) { return apply_function<double>(std::sinh, x); } |
---|
| 122 | //! Sine hyperbolic function |
---|
| 123 | inline mat sinh(const mat &x) { return apply_function<double>(std::sinh, x); } |
---|
| 124 | //! Cosine hyperbolic function |
---|
| 125 | inline vec cosh(const vec &x) { return apply_function<double>(std::cosh, x); } |
---|
| 126 | //! Cosine hyperbolic function |
---|
| 127 | inline mat cosh(const mat &x) { return apply_function<double>(std::cosh, x); } |
---|
| 128 | //! Tan hyperbolic function |
---|
| 129 | inline vec tanh(const vec &x) { return apply_function<double>(std::tanh, x); } |
---|
| 130 | //! Tan hyperbolic function |
---|
| 131 | inline mat tanh(const mat &x) { return apply_function<double>(std::tanh, x); } |
---|
| 132 | //! Inverse sine hyperbolic function |
---|
| 133 | inline vec asinh(const vec &x) { return apply_function<double>(::asinh, x); } |
---|
| 134 | //! Inverse sine hyperbolic function |
---|
| 135 | inline mat asinh(const mat &x) { return apply_function<double>(::asinh, x); } |
---|
| 136 | //! Inverse cosine hyperbolic function |
---|
| 137 | inline vec acosh(const vec &x) { return apply_function<double>(::acosh, x); } |
---|
| 138 | //! Inverse cosine hyperbolic function |
---|
| 139 | inline mat acosh(const mat &x) { return apply_function<double>(::acosh, x); } |
---|
| 140 | //! Inverse tan hyperbolic function |
---|
| 141 | inline vec atanh(const vec &x) { return apply_function<double>(::atanh, x); } |
---|
| 142 | //! Inverse tan hyperbolic function |
---|
| 143 | inline mat atanh(const mat &x) { return apply_function<double>(::atanh, x); } |
---|
| 144 | |
---|
| 145 | //!@} |
---|
| 146 | |
---|
| 147 | } // namespace itpp |
---|
| 148 | |
---|
| 149 | #endif // #ifndef TRIG_HYP_H |
---|