Created
October 21, 2021 17:31
-
-
Save PentaHelix/ff4a693c509d881ab820ff7c90f98cf7 to your computer and use it in GitHub Desktop.
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
f2 = lambda x : 1/(1+x**2) | |
lam_cheb = [] | |
lam_unif = [] | |
ns = range(5,45,5) | |
for n in ns: | |
x_unif = [5*(-1 + 2*i/n) for i in range(n+1)] | |
x_cheb = chebyshev(-5, 5, n) | |
y_unif = [f2(x) for x in x_unif] | |
y_cheb = [f2(x) for x in x_cheb] | |
lin = np.linspace(-5,5,n*3) | |
pyplot.plot(lin, [interp(x_cheb, y_cheb, x) for x in lin], label='Chebyshev') | |
pyplot.plot(lin, [interp(x_unif, y_unif, x) for x in lin], label='Uniform') | |
pyplot.ylim((-1.5, 1.5)) | |
pyplot.legend() | |
pyplot.show() | |
def lam (xs, at): | |
return sum([abs(interp(xs, [1 if j == i else 0 for j in range(n+1)], at)) for i in range(n+1)]) | |
lam_cheb.append(max([lam(x_cheb, at) for at in lin])) | |
lam_unif.append(max([lam(x_unif, at) for at in lin])) | |
pyplot.semilogy(ns, lam_unif, label='Lambda Uniform') | |
pyplot.semilogy(ns, lam_cheb, label='Lambda Chebyshev') | |
pyplot.legend() | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment