Math 256x: The Theory of Error-Correcting Codes (Fall 2013)

Sage code for Krawtchouk K10, K11 (q=3 and n=150)



def K(n,q,i,x):
    return sum( (-1)^j * (q-1)^(i-j) * binomial(x,j) * binomial(n-x,i-j) for j in [0..i])

def K1(n,q,i,x):
    return K(n,q,i,x) * sqrt((q-1)^x * factorial(n) / (q^n * factorial(x)*factorial(n-x))) 

def K2(n,q,i,x):
    return K1(n,q,i,x) / sqrt((q-1)^i * binomial(n,i))

def f10(x):
    return K2(150.,3,10,x)

def f11(x):
    return K2(150.,3,11,x)
    
H10 = plot(f10,(x,0,150),plot_points=2000,color="red")
H11 = plot(f11,(x,0,150),plot_points=2000,color="blue")
(H10+H11).show()