[Tutor] more precision/predictability in calculations

Prahlad Vaidyanathan slime@vsnl.net
Fri, 13 Sep 2002 11:53:19 +0530


Hi,

[ Note: This mail contains quite a bit of Math, so if you
don't like math, please ignore it ]

    I have just written some code that looks like this :

"""
def diff2 (fn, var, x0, y0, epsilon=0.0001) :
    """ Given a 2 variable function, differentiates it partially
    w.r.t 'var', at the point (x0, y0) """
    if var == "x" :
        return (fn(x0+epsilon, y0) - fn(x0, y0))/epsilon
    elif var == "y" :
        return (fn(x0, y0+epsilon) - fn(x0, y0))/epsilon

def satisfies_cr_eqns (u, v, z0) :
    """Checks if the 2 real-valued functions 'u' and 'v' satisfy
    the Cauchy-Reimann equations at z0"""
    ux = diff2(u, "x", z0.real, z0.imag) ##; print ux
    uy = diff2(u, "y", z0.real, z0.imag) ##; print uy
    vx = diff2(v, "x", z0.real, z0.imag) ##; print vx
    vy = diff2(v, "y", z0.real, z0.imag) ##; print vy
    ## return ux == vy and uy == -vx
    return (ux - vy) < pow(10,-3) and (uy + vx) < pow(10, -3)

"""

    Now, I construct 2 functions like so :

"""

def f1(a, b) :
    return pow(math.e, a) * math.cos(b)

def f2(a, b) :
    return pow(math.e, a) * math.sin(b)

"""

    These 2 functions do satisfy the c-r equations for any point
in the complex plane. But, when I run satisfy_cr_eqns(), it
returns true for some points and false for others. I presumed
that the higher the value of the complex number, the lower the
precision would be. But, the function turns out to be true for
complex(99,99), and false for complex(3,3) !!

    I know this may be asking too much of Python, but is there
any way I can make these calculations more precise ? or, at least
more predictable ? :-)

    Do let me know. Thanks.

pv.
-- 
Prahlad Vaidyanathan  <http://www.symonds.net/~prahladv/>

If all the world's a stage, I want to operate the trap door.
		-- Paul Beatty