ILI285 - Computación Científica I / INF285 - Computación Científica

Finding 2 Chebyshev points graphycally

[S]cientific [C]omputing [T]eam

Version: 1.02


In [1]:
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib as mpl
mpl.rcParams['font.size'] = 14
mpl.rcParams['axes.labelsize'] = 20
mpl.rcParams['xtick.labelsize'] = 14
mpl.rcParams['ytick.labelsize'] = 14
%matplotlib inline

Finding 2 Chebyshev points

We compute them so we can compare them later.


In [2]:
n=2
i=1
theta1=(2*i-1)*np.pi/(2*n)
i=2
theta2=(2*i-1)*np.pi/(2*n)
c1=np.cos(theta1)
c2=np.cos(theta2)

Recall that the Chebyshev points are points that minimize the following expression: $$ \displaystyle{\omega(x_1,x_2,\dots,x_n)=\max_{x} |(x-x_1)\,(x-x_2)\,\cdots\,(x-x_n)|}. $$ This comes from the Interpolation Error Formula (I hope you remember it, otherwise see the textbook or the classnotes!). In this notebook, we will find the $\min$ for 2 points, this means: $$ [x_1,x_2]= \displaystyle{\mathop{\mathrm{argmin}}_{x_1,x_2}} \,\omega(x_1,x_2)=\displaystyle{\mathop{\mathrm{argmin}}_{x_1,x_2}}\, \max_{x} |(x-x_1)\,(x-x_2)|. $$ For doing this, we first need to build $\omega(x_1,x_2)$,


In [3]:
N=50
x=np.linspace(-1,1,N)
w = lambda x1,x2: np.max(np.abs((x-x1)*(x-x2)))
wv=np.vectorize(w)

Now we need to evaluate $\omega(x_1,x_2)$ over the domain $\Omega=[0,1]^2$.


In [4]:
[X,Y]=np.meshgrid(x,x)
W=wv(X,Y)

With this data, we can now plot the function $\omega(x_1,x_2)$ on $\Omega$. The minimun value of is shown by the color at the bottom of the colorbar. By visual inspection, we see that we have two mins. They are located at the bottom right and top left.


In [5]:
plt.figure(figsize=(8,8))
plt.contourf(X, Y, W,100, cmap=cm.hsv, antialiased=False)
plt.xlabel(r'$x_1$')
plt.ylabel(r'$x_2$')
plt.colorbar()
plt.show()


Finally, we have included the min in the plot and we see the agreement between the min of $\omega(x_1,x_2)$ and the Chebyshev points found.


In [6]:
plt.figure(figsize=(8,8))
plt.contourf(X, Y, W,100, cmap=cm.hsv, antialiased=False)
plt.plot(c1,c2,'k.',markersize=16)
plt.plot(c2,c1,'k.',markersize=16)
plt.colorbar()
plt.xlabel(r'$x_1$') 
plt.ylabel(r'$x_2$')
plt.show()


Python Modules and Functions

Acknowledgements

  • Material created by professor Claudio Torres (ctorres@inf.utfsm.cl). DI UTFSM. May 2018.
  • Update June 2020 - v1.02 - C.Torres : Fixing formatting issues.

In [ ]: