Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

another try:

put the functions in a python dictionary with the respective intervals as keys.

run through the sorted keys and add up the integrals for each fitting interval

from scipy.constants import h, c, k

a=11717

f1(x) = a*(x**-0.53)
f2(x) = a*(x**-0.75)

T = {(1,10000):f1,(10000,20000):f2, (20000,50000):f1}


# Blackbody Planky function
def B(Lambda,Temp):
    return 2*h*c**2/(Lambda**5 *(exp(h*c/(Lambda*k*Temp))-1))

a1 = 300; a2 = 22000  # interval

def flux2(Lambda):
    sum = 0   
    L = copy(T.keys())
    L.sort()
    for k in L:
        if k[1] <= a1: continue
        if k[0] <= a1 and a2 <= k[1]:
            print 'one: key=',k, 'interval from', a1, 'to', a2
            return numerical_integral(2*pi*x*B( Lambda,T[k]),a1,a2)[0]            
        if k[0] <= a1: 
            print 'two: key=',k, 'interval from', a1, 'to', k[1]
            sum += numerical_integral(2*pi*x*B( Lambda,T[k]),a1,k[1])[0]
            continue
        if a1 <= k[0] and k[1] <= a2:
            print 'three: key=',k, 'interval from', k[0], 'to', k[1]
            sum += numerical_integral(2*pi*x*B( Lambda,T[k]),k[0],k[1])[0]
            continue
        if k[0] <= a2 <= k[1]:
            print 'four: key=',k, 'interval from', k[0], 'to', a2
            sum += numerical_integral(2*pi*x*B( Lambda,T[k]),k[0],a2)[0]
        if a1 >= k[1]:
            pass            
    return sum

print 2.5*log(flux2(9000*10**-10))