Post Reply 
PYTHON program not work
09-05-2021, 08:54 AM
Post: #2
RE: PYTHON program not work
I figured out how to run the program: see the code
Code:
#PYTHON EXPORT nome
from math import *
from sys import *
a=argv[0];
b=argv[1];
x=argv[2];
a=float(a);
b=float(b);
x=float(x);

def contfractbeta(a,b,x, ITMAX = 200):
     
    """ contfractbeta() evaluates the continued fraction form of the incomplete Beta function; incompbeta().  
    (Code translated from: Numerical Recipes in C.)"""
     
    EPS = 3.0e-7
    bm = az = am = 1.0
    qab = a+b
    qap = a+1.0
    qam = a-1.0
    bz = 1.0-qab*x/qap
     
    for i in range(ITMAX+1):
        em = float(i+1)
        tem = em + em
        d = em*(b-em)*x/((qam+tem)*(a+tem))
        ap = az + d*am
        bp = bz+d*bm
        d = -(a+em)*(qab+em)*x/((qap+tem)*(a+tem))
        app = ap+d*az
        bpp = bp+d*bz
        aold = az
        am = ap/bpp
        bm = bp/bpp
        az = app/bpp
        bz = 1.0
        if (abs(az-aold)<(EPS*abs(az))):
            return az
            
def incompbeta(a, b, x):
     
    ''' incompbeta(a,b,x) evaluates incomplete beta function, here a, b > 0 and 0 <= x <= 1. This function requires contfractbeta(a,b,x, ITMAX = 200) 
    (Code translated from: Numerical Recipes in C.)'''
     
    if (x == 0):
        return 0;
    elif (x == 1):
        return 1;
    else:
        lbeta = lgamma(a+b) - lgamma(a) - lgamma(b) + a * log(x) + b * log(1-x)
        if (x < (a+1) / (a+b+2)):
            return exp(lbeta) * contfractbeta(a, b, x) / a;
        else:
            return 1 - exp(lbeta) * contfractbeta(b, a, 1-x) / b;
print(incompbeta(a,b,x));
#end

EXPORT BetaRegInc(a,b,x)
BEGIN
PYTHON(nome,a,b,x);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
PYTHON program not work - robmio - 09-05-2021, 05:59 AM
RE: PYTHON program not work - robmio - 09-05-2021 08:54 AM
RE: PYTHON program not work - robmio - 09-05-2021, 11:06 AM
RE: PYTHON program not work - Albert Chan - 09-05-2021, 03:58 PM
RE: PYTHON program not work - robmio - 09-05-2021, 04:54 PM



User(s) browsing this thread: 1 Guest(s)