1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
.. _math:
Common Math Functions (HOC)
---------------------------
These math functions return a double precision value and take a double
precision argument. The exception is :func:`atan2` which has two double precision arguments.
Diagnostics:
Arguments that are out of range give an argument domain diagnostic.
These functions call the library routines supplied by the compiler.
----
.. function:: abs
absolute value
.. code-block::
none
>>> h.abs(-42.2)
42.2
See :meth:`Vector.abs` for the :class:`Vector` class.
.. note::
In Python code, use Python's ``abs`` function, which works on both numbers and numpy arrays, as well as Vectors (Vectors do not print their contents) :
.. code-block::
python
>>> abs(-42.2)
42.2
>>> abs(-3 + 4j)
5.0
>>> v = h.Vector([1, 6, -2, -65])
>>> abs(v).printf()
1 6 2 65
4
----
.. function:: int
returns the integer part of its argument (truncates toward 0).
.. code-block::
none
>>> h.int(3.14)
3.0
>>> h.int(-3.14)
-3.0
.. note::
In Python code, use Python's ``int`` function instead. The behavior is slightly different in that the Python function returns an int type instead of a double:
.. code-block::
python
>>> int(-3.14)
-3
>>> int(3.14)
3
----
.. function:: sqrt
square root
see :meth:`Vector.sqrt` for the :class:`Vector` class.
.. note::
Consider using Python's built in ``math.sqrt`` instead.
----
.. function:: exp
Description:
returns the exponential function to the base e
When exp is used in model descriptions, it is often the
case that the cvode variable step integrator extrapolates
voltages to values which return out of range values for the exp (often used
in rate functions). There were so many of these false warnings that it was
deemed better to turn off the warning message when Cvode is active.
In any case the return value is exp(700). This message is not turned off
at the interpreter level or when cvode is not active.
.. code-block::
python
from neuron import h
for i in range(6,12):
print('%g %g' % (i, h.exp(i)))
.. note::
Consider using Python's built in ``math.exp`` instead.
----
.. function:: log
logarithm to the base e
see :meth:`Vector.log` for the :class:`Vector` class.
.. note::
Consider using Python's built in ``math.log`` instead.
----
.. function:: log10
logarithm to the base 10
see :meth:`Vector.log10` for the :class:`Vector` class.
.. note::
Consider using Python's built in ``math.log10`` instead.
----
.. function:: cos
trigonometric function of radian argument.
see :meth:`Vector.sin`
.. note::
Consider using Python's built in ``math.cos`` instead.
----
.. function:: sin
trigonometric function of radian argument.
see :meth:`Vector.sin` for the :class:`Vector` class.
.. note::
Consider using Python's built in ``math.sin`` instead.
----
.. function:: tanh
hyperbolic tangent.
see :meth:`Vector.tanh` for the :class:`Vector` class.
.. note::
Consider using Python's built in ``math.tanh`` instead.
----
.. function:: atan
returns the arc-tangent of y/x in the range :math:`-\pi/2` to :math:`\pi/2`. (x > 0)
.. note::
Consider using Python's built in ``math.atan`` instead.
----
.. function:: atan2
Syntax:
``radians = atan2(y, x)``
Description:
returns the arc-tangent of y/x in the range :math:`-\pi` < radians <= :math:`\pi`. y and x
can be any double precision value, including 0. If both are 0 the value
returned is 0.
Imagine a right triangle with base x and height y. The result
is the angle in radians between the base and hypotenuse.
Example:
.. code-block::
python
from neuron import h
h.atan2(0,0)
for i in range(-1,2):
print(h.atan2(i*1e-6, 10))
for i in range(-1,2):
print(h.atan2(i*1e-6, -10))
for i in range(-1,2):
print(h.atan2(10, i*1e-6))
for i in range(-1,2):
print(h.atan2(-10, i*1e-6))
h.atan2(10,10)
h.atan2(10,-10)
h.atan2(-10,10)
h.atan2(-10,-10)
.. note::
Consider using Python's built in ``math.atan2`` instead.
----
.. function:: erf
normalized error function
.. math::
{\rm erf}(z) = \frac{2}{\sqrt{\pi}} \int_{0}^{z} e^{-t^2} dt
.. note::
In Python 3.2+, use ``math.erf`` instead.
----
.. function:: erfc
returns ``1.0 - erf(z)`` but on sun machines computed by other methods
that avoid cancellation for large z.
.. note::
In Python 3.2+, use ``math.erfc`` instead.
|