efuncs.py :  » Math » Matrix-package-for-Python » MatPy-0.4.0 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Math » Matrix package for Python 
Matrix package for Python » MatPy 0.4.0 » efuncs.py
#!/usr/bin/env python
# (C) 2000 Huaiyu Zhu <hzhu@users.sourceforge.net>.  Licence: GPL
# $Id: efuncs.py,v 1.9 2001/08/26 12:40:43 hzhu Exp $
"""
efuncs.py - element-wise functions

The following do not allow complex operations:
abs, ceil, floor, sign, gam, lgam, igam, igamc, igami, beta, lbeta, ibeta,
ibetai, psi, rgam,

The following allow complex operations:
sqrt, sinc, exp, log, log10, sinh, cosh, tanh, asinh, sin, cos, tan, asin,
acos, atan,

For functions that maps reals to reals the complex operations are only used
when the argument is complex (using efuncRC)

"""

import cephes
import MLab
from MatPy.Matrix import efunc,efuncC,efuncRC

#------------------------------------------------------------------
"Miscellenious functions"

def abs(x):
  "abs(x) : elementwise absolute value of x"
  return efunc(MLab.absolute, x)

def ceil(x):
  "ceil(x) : elementwise smallest integer not less than x"
  return efunc(MLab.ceil, x)

def floor(x):
  "floor(x) : elementwise largest integer not greater than x"
  return efunc(MLab.floor, x)

def sign(x):
  "sign(x) : elementwise sign of x in (-1, 0, +1)"
  return efunc(MLab.sign, x)

def triu(x, k=0):
  """triu(x, k=0) : upper triangular part (on >=k)-th diagonal) of x.
  k > 0 is above andk < 0 is below the main diagonal.  """
  return efunc(MLab.triu, x, k)

def tril(x, k=0):
  """ tril(x, k=0) : lower triangular part (on <=k-th diagonal) of x.
  k > 0 is above and k < 0 is below the main diagonal. """
  return efunc(MLab.triu, x, k)


#------------------------------------------------------------------
def sqrt(x):
  "sqrt(x) : elementwise square root of x"
  return efuncC(MLab.sqrt, x)

def sinc(x):
  "sinc(x) : elementwise sin(x)/x"
  return efuncRC(MLab.sinc, x)

#------------------------------------------------------------------
"Exponential and related functions"

def exp(x):
  "exp(x) : elementwise exponential of x"
  return efuncRC(MLab.exp, x)

def log(x):
  "log(x) : elementwise logarithm of x base e"
  return efuncC(MLab.log, x)

def log10(x):
  "log10(x) : elementwise logarithm of x base 10"
  return efuncC(MLab.log10, x)

def sinh(x):
  "sinh(x) : elementwise hyperbolic sine of x"
  return efuncRC(MLab.sinh, x)

def cosh(x):
  "cosh(x) : elementwise hyperbolic cosine of x"
  return efuncRC(MLab.cosh, x)

def tanh(x):
  "tanh(x) : elementwise hyperbolic tangent of x"
  return efuncRC(MLab.tanh, x)

#------------------------------------------------------------------
def asinh(x):
  "asinh(x) : elementwise inverse hyperbolic sine of x"
  return log(x+sqrt(x.__tpow__(2)+1.))

#------------------------------------------------------------------
"Trigonmetric and related functions"

def sin(x):
  "sin(x) : elementwise sine of x"
  return efuncRC(MLab.sin, x)

def cos(x):
  "cose(x) : elementwise cosine of x"
  return efuncRC(MLab.cos, x)

def tan(x):
  "tan(x) : elementwise tangent of x"
  return efuncRC(MLab.tan, x)

def asin(x):
  "asin(x) : elementwise arc sine of x"
  return efuncC(MLab.arcsin, x)

def acos(x):
  "acos(x) : elementwise arc cosine of x"
  return efuncC(MLab.arccos, x)

def atan(x):
  "atan(x) : elementwise arc tangent of x"
  return efuncC(MLab.arctan, x)


#------------------------------------------------------------------
"Gamma and related functions"

def gam(x):
  "gam(x) : elementwise gamma function of x"
  return efunc(cephes.gamma, x)

def lgam(x):
  "lgam(x) : elementwise log gam |x|"
  return efunc(cephes.lgam, x)

def igam(x):
  """igam(x>0, a>0) : elementwise incomplete gamma integral
  = 1 / gam(a) * integral(exp(-t) * t**(a-1), t=0..x).
  """
  return efunc(cephes.igam, a, x)

def igamc(x, a):
  """igamc(x>0,a>0) : elementwise complemented incomplete gamma integral
  = 1 / gam(a) * integral(exp(-t) * t**(a-1), t=x..inf) = 1 - igam(a,x).
  """
  return efunc(cephes.igamc, a, x)

def igami(y, a):
  """igami(y, a>=0) : elementwise inverse incomplete gamma integral
  = x such that igamc(a,x) = y"""
  return efunc(cephes.igami, a, y)

def beta(a, b):
  "beta(a,b) : elementwise beta function = gamma(a) * gamma(b) / gamma(a+b)"
  return efunc(cephes.beta, a, b)

def lbeta(a, b):
  "lbeta(a,b) : elementwise log |beta(x)|"
  return efunc(cephes.lbeta, a, b)

def ibeta(x, a, b):
  """ibeta(x,a,b) : elementwise incomplete beta integral of x,
  = 1 / beta(a,b) * integral(t**(a-1) (1-t)**(b-1), t=0..x) """
  return efunc(cephes.incbet, a, b, x)

def ibetai(y, a, b):
  """ibetai(y, a>=0, b>=0) : elementwise inverse incomplete beta integral
  = x such that ibetai(x,a,b) = y"""
  return efunc(cephes.ibetai, a, b, y)

def psi(x):
  "psi(x) : elementwise derivative of log gam(x)"
  return efunc(cephes.psi, x)

def rgam(x):
  "rgam(x) : elementwise 1 / gam(x)" 
  return efunc(cephes.rgamma, x)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.