Created
May 2, 2013 11:08
-
-
Save niklasf/5501532 to your computer and use it in GitHub Desktop.
Calculate the lebesgue constant of a polynomial interpolation operator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
n = 20 | |
#x_k = [-1 + 2 * k / float(n) for k in range(0, n + 1)] | |
x_k = [math.cos((2.0 * k + 1) / (2.0 * n +2.0) * math.pi) | |
for k in range(0, n + 1)] | |
def l_j(j, x): | |
product = 1.0 | |
for i in range(0, n + 1): | |
if i != j: | |
product *= (x - x_k[i]) / (x_k[j] - x_k[i]) | |
return product | |
def y(x): | |
csum = 0 | |
for j in range(0, n + 1): | |
csum += abs(l_j(j, x)) | |
return csum | |
def drange(start, stop, step): | |
r = start | |
while r < stop: | |
yield r | |
r += step | |
def d(): | |
greatest = None | |
for x in drange(-1.0, 1.0, 0.000001): | |
current = y(x) | |
if greatest is None or current > greatest: | |
greatest = current | |
return greatest | |
print d() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment