NAME

PDL::Math - extended mathematical operations and special functions

SYNOPSIS

use PDL::Math;

use PDL::Graphics::TriD;
imag3d [SURF2D,bessj0(rvals(zeroes(50,50))/2)];

DESCRIPTION

This module extends PDL with more advanced mathematical functions than provided by standard Perl.

All the functions have one input pdl, and one output, unless otherwise stated.

Many of the functions are linked from the system maths library or the Cephes maths library (determined when PDL is compiled); a few are implemented entirely in PDL.

FUNCTIONS

acos

Signature: (a(); [o]b())
Types: (cfloat cdouble cldouble float double ldouble)
$b = acos($a);
acos($a, $b);      # all arguments given
$b = $a->acos;     # method call
$a->acos($b);
$a->inplace->acos; # can be used inplace
acos($a->inplace);

The usual trigonometric function.

Broadcasts over its inputs.

acos processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

asin

Signature: (a(); [o]b())
Types: (cfloat cdouble cldouble float double ldouble)
$b = asin($a);
asin($a, $b);      # all arguments given
$b = $a->asin;     # method call
$a->asin($b);
$a->inplace->asin; # can be used inplace
asin($a->inplace);

The usual trigonometric function.

Broadcasts over its inputs.

asin processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

atan

Signature: (a(); [o]b())
Types: (cfloat cdouble cldouble float double ldouble)
$b = atan($a);
atan($a, $b);      # all arguments given
$b = $a->atan;     # method call
$a->atan($b);
$a->inplace->atan; # can be used inplace
atan($a->inplace);

The usual trigonometric function.

Broadcasts over its inputs.

atan processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

cosh

Signature: (a(); [o]b())
Types: (cfloat cdouble cldouble float double ldouble)
$b = cosh($a);
cosh($a, $b);      # all arguments given
$b = $a->cosh;     # method call
$a->cosh($b);
$a->inplace->cosh; # can be used inplace
cosh($a->inplace);

The standard hyperbolic function.

Broadcasts over its inputs.

cosh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

sinh

Signature: (a(); [o]b())
Types: (cfloat cdouble cldouble float double ldouble)
$b = sinh($a);
sinh($a, $b);      # all arguments given
$b = $a->sinh;     # method call
$a->sinh($b);
$a->inplace->sinh; # can be used inplace
sinh($a->inplace);

The standard hyperbolic function.

Broadcasts over its inputs.

sinh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

tan

Signature: (a(); [o]b())
Types: (cfloat cdouble cldouble float double ldouble)
$b = tan($a);
tan($a, $b);      # all arguments given
$b = $a->tan;     # method call
$a->tan($b);
$a->inplace->tan; # can be used inplace
tan($a->inplace);

The usual trigonometric function.

Broadcasts over its inputs.

tan processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

tanh

Signature: (a(); [o]b())
Types: (cfloat cdouble cldouble float double ldouble)
$b = tanh($a);
tanh($a, $b);      # all arguments given
$b = $a->tanh;     # method call
$a->tanh($b);
$a->inplace->tanh; # can be used inplace
tanh($a->inplace);

The standard hyperbolic function.

Broadcasts over its inputs.

tanh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

ceil

Signature: (a(); [o]b())
Types: (sbyte byte short ushort long ulong indx ulonglong longlong
  float double ldouble)
$b = ceil($a);
ceil($a, $b);      # all arguments given
$b = $a->ceil;     # method call
$a->ceil($b);
$a->inplace->ceil; # can be used inplace
ceil($a->inplace);

Round to integer values in floating-point format.

Broadcasts over its inputs.

ceil processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

floor

Signature: (a(); [o]b())
Types: (sbyte byte short ushort long ulong indx ulonglong longlong
  float double ldouble)
$b = floor($a);
floor($a, $b);      # all arguments given
$b = $a->floor;     # method call
$a->floor($b);
$a->inplace->floor; # can be used inplace
floor($a->inplace);

Round to integer values in floating-point format.

Broadcasts over its inputs.

floor processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

rint

Signature: (a(); [o]b())
Types: (sbyte byte short ushort long ulong indx ulonglong longlong
  float double ldouble)
$b = rint($a);
rint($a, $b);      # all arguments given
$b = $a->rint;     # method call
$a->rint($b);
$a->inplace->rint; # can be used inplace
rint($a->inplace);

Round to integer values in floating-point format.

This is the C99 function; previous to 2.096, the doc referred to a bespoke function that did banker's rounding, but this was not used as a system version will have been detected and used.

If you are looking to round half-integers up (regardless of sign), try floor($x+0.5). If you want to round half-integers away from zero, try ceil(abs($x)+0.5)*($x<=>0).

Broadcasts over its inputs.

rint processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

pow

Signature: (a(); b(); [o]c())
Types: (cfloat cdouble cldouble sbyte byte short ushort long
  ulong indx ulonglong longlong float double ldouble)
$c = pow($a, $b);
pow($a, $b, $c);      # all arguments given
$c = $a->pow($b);     # method call
$a->pow($b, $c);
$a->inplace->pow($b); # can be used inplace
pow($a->inplace,$b);

Synonym for `**'.

Broadcasts over its inputs.

pow processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

acosh

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = acosh($a);
acosh($a, $b);      # all arguments given
$b = $a->acosh;     # method call
$a->acosh($b);
$a->inplace->acosh; # can be used inplace
acosh($a->inplace);

The standard hyperbolic function.

Broadcasts over its inputs.

acosh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

asinh

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = asinh($a);
asinh($a, $b);      # all arguments given
$b = $a->asinh;     # method call
$a->asinh($b);
$a->inplace->asinh; # can be used inplace
asinh($a->inplace);

The standard hyperbolic function.

Broadcasts over its inputs.

asinh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

atanh

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = atanh($a);
atanh($a, $b);      # all arguments given
$b = $a->atanh;     # method call
$a->atanh($b);
$a->inplace->atanh; # can be used inplace
atanh($a->inplace);

The standard hyperbolic function.

Broadcasts over its inputs.

atanh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

erf

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = erf($a);
erf($a, $b);      # all arguments given
$b = $a->erf;     # method call
$a->erf($b);
$a->inplace->erf; # can be used inplace
erf($a->inplace);

The error function.

Broadcasts over its inputs.

erf processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

erfc

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = erfc($a);
erfc($a, $b);      # all arguments given
$b = $a->erfc;     # method call
$a->erfc($b);
$a->inplace->erfc; # can be used inplace
erfc($a->inplace);

The complement of the error function.

Broadcasts over its inputs.

erfc processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

bessj0

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = bessj0($a);
bessj0($a, $b);      # all arguments given
$b = $a->bessj0;     # method call
$a->bessj0($b);
$a->inplace->bessj0; # can be used inplace
bessj0($a->inplace);

The regular Bessel function of the first kind, J_n

Broadcasts over its inputs.

bessj0 processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

bessj1

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = bessj1($a);
bessj1($a, $b);      # all arguments given
$b = $a->bessj1;     # method call
$a->bessj1($b);
$a->inplace->bessj1; # can be used inplace
bessj1($a->inplace);

The regular Bessel function of the first kind, J_n

Broadcasts over its inputs.

bessj1 processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

bessy0

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = bessy0($a);
bessy0($a, $b);      # all arguments given
$b = $a->bessy0;     # method call
$a->bessy0($b);
$a->inplace->bessy0; # can be used inplace
bessy0($a->inplace);

The regular Bessel function of the second kind, Y_n.

Broadcasts over its inputs.

bessy0 processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

bessy1

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = bessy1($a);
bessy1($a, $b);      # all arguments given
$b = $a->bessy1;     # method call
$a->bessy1($b);
$a->inplace->bessy1; # can be used inplace
bessy1($a->inplace);

The regular Bessel function of the second kind, Y_n.

Broadcasts over its inputs.

bessy1 processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

bessjn

Signature: (a(); int n(); [o]b())
Types: (float double ldouble)
$b = bessjn($a, $n);
bessjn($a, $n, $b);      # all arguments given
$b = $a->bessjn($n);     # method call
$a->bessjn($n, $b);
$a->inplace->bessjn($n); # can be used inplace
bessjn($a->inplace,$n);

The regular Bessel function of the first kind, J_n . This takes a second int argument which gives the order of the function required.

Broadcasts over its inputs.

bessjn processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

bessyn

Signature: (a(); int n(); [o]b())
Types: (float double ldouble)
$b = bessyn($a, $n);
bessyn($a, $n, $b);      # all arguments given
$b = $a->bessyn($n);     # method call
$a->bessyn($n, $b);
$a->inplace->bessyn($n); # can be used inplace
bessyn($a->inplace,$n);

The regular Bessel function of the first kind, Y_n . This takes a second int argument which gives the order of the function required.

Broadcasts over its inputs.

bessyn processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

lgamma

Signature: (a(); [o]b(); int[o]s())
Types: (sbyte byte short ushort long ulong indx ulonglong longlong
  float double ldouble)
($b, $s) = lgamma($a);
lgamma($a, $b, $s);    # all arguments given
($b, $s) = $a->lgamma; # method call
$a->lgamma($b, $s);

log gamma function

This returns 2 ndarrays -- the first set gives the log(gamma) values, while the second set, of integer values, gives the sign of the gamma function. This is useful for determining factorials, amongst other things.

Broadcasts over its inputs.

lgamma processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

isfinite

Signature: (a(); int [o]mask())
Types: (sbyte byte short ushort long ulong indx ulonglong longlong
  float double ldouble)
$mask = isfinite($a);
isfinite($a, $mask);  # all arguments given
$mask = $a->isfinite; # method call
$a->isfinite($mask);

Sets $mask true if $a is not a NaN or inf (either positive or negative).

Broadcasts over its inputs.

Bad values are treated as NaN or inf.

erfi

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = erfi($a);
erfi($a, $b);      # all arguments given
$b = $a->erfi;     # method call
$a->erfi($b);
$a->inplace->erfi; # can be used inplace
erfi($a->inplace);

erfi

Broadcasts over its inputs.

erfi processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

ndtri

Signature: (a(); [o]b())
Types: (float double ldouble)
$b = ndtri($a);
ndtri($a, $b);      # all arguments given
$b = $a->ndtri;     # method call
$a->ndtri($b);
$a->inplace->ndtri; # can be used inplace
ndtri($a->inplace);

ndtri

Broadcasts over its inputs.

ndtri processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

polyroots

Signature: (cr(n); ci(n); [o]rr(m=CALC($SIZE(n)-1)); [o]ri(m))
Types: (double)

Complex roots of a complex polynomial, given coefficients in order of decreasing powers. Only works for degree >= 1. Uses the Jenkins-Traub algorithm (see https://en.wikipedia.org/wiki/Jenkins%E2%80%93Traub_algorithm). As of 2.086, works with native-complex data.

$roots = polyroots($coeffs); # native complex
polyroots($coeffs, $roots=null); # native complex
($rr, $ri) = polyroots($cr, $ci);
polyroots($cr, $ci, $rr, $ri);

Broadcasts over its inputs.

polyroots does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

polyfromroots

Signature: (r(m); [o]c(n=CALC($SIZE(m)+1)))
Types: (cdouble)

Calculates the complex coefficients of a polynomial from its complex roots, in order of decreasing powers. Added in 2.086, works with native-complex data.

Algorithm is from Octave poly.m, O(n^2), per https://cs.stackexchange.com/questions/116643/what-is-the-most-efficient-algorithm-to-compute-polynomial-coefficients-from-its; using an FFT would allow O(n*log(n)^2).

$coeffs = polyfromroots($roots); # native complex
($cr, $ci) = polyfromroots($rr, $ri);

Broadcasts over its inputs.

polyfromroots does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

polyval

Signature: (c(n); x(); [o]y())
Types: (cdouble)

Complex value of a complex polynomial at given point, given coefficients in order of decreasing powers. Uses Horner recurrence. Added in 2.086, works with native-complex data.

$y = polyval($coeffs, $x); # native complex
($yr, $yi) = polyval($cr, $ci, $xr, $xi);

Broadcasts over its inputs.

polyval does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

csqrt

Signature: (i(); complex [o] o())
Types: (float ldouble cfloat cdouble cldouble double)
$o = csqrt($i);
csqrt($i, $o);  # all arguments given
$o = $i->csqrt; # method call
$i->csqrt($o);

Takes real or complex data, returns the complex sqrt.

Added in 2.099.

Broadcasts over its inputs.

csqrt does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

clog

Signature: (i(); complex [o] o())
Types: (float ldouble cfloat cdouble cldouble double)
$o = clog($i);
clog($i, $o);  # all arguments given
$o = $i->clog; # method call
$i->clog($o);

Takes real or complex data, returns the complex log.

Added in 2.099.

Broadcasts over its inputs.

clog does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

cacos

Signature: (i(); complex [o] o())
Types: (float ldouble cfloat cdouble cldouble double)
$o = cacos($i);
cacos($i, $o);  # all arguments given
$o = $i->cacos; # method call
$i->cacos($o);

Takes real or complex data, returns the complex acos.

Added in 2.099.

Broadcasts over its inputs.

cacos does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

casin

Signature: (i(); complex [o] o())
Types: (float ldouble cfloat cdouble cldouble double)
$o = casin($i);
casin($i, $o);  # all arguments given
$o = $i->casin; # method call
$i->casin($o);

Takes real or complex data, returns the complex asin.

Added in 2.099.

Broadcasts over its inputs.

casin does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

cacosh

Signature: (i(); complex [o] o())
Types: (float ldouble cfloat cdouble cldouble double)
$o = cacosh($i);
cacosh($i, $o);  # all arguments given
$o = $i->cacosh; # method call
$i->cacosh($o);

Takes real or complex data, returns the complex acosh.

Added in 2.099.

Broadcasts over its inputs.

cacosh does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

catanh

Signature: (i(); complex [o] o())
Types: (float ldouble cfloat cdouble cldouble double)
$o = catanh($i);
catanh($i, $o);  # all arguments given
$o = $i->catanh; # method call
$i->catanh($o);

Takes real or complex data, returns the complex atanh.

Added in 2.099.

Broadcasts over its inputs.

catanh does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

csqrt_up

Signature: (i(); complex [o] o())
Types: (float ldouble cfloat cdouble cldouble double)
$o = csqrt_up($i);
csqrt_up($i, $o);  # all arguments given
$o = $i->csqrt_up; # method call
$i->csqrt_up($o);

Take the complex square root of a number choosing that whose imaginary part is not negative, i.e., it is a square root with a branch cut 'infinitesimally' below the positive real axis.

Broadcasts over its inputs.

csqrt_up does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

AUTHOR

Copyright (C) R.J.R. Williams 1997 (rjrw@ast.leeds.ac.uk), Karl Glazebrook (kgb@aaoepp.aao.gov.au) and Tuomas J. Lukka (Tuomas.Lukka@helsinki.fi). Portions (C) Craig DeForest 2002 (deforest@boulder.swri.edu).

All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the PDL copyright notice should be included in the file.