Chebyshev

1132 days ago by ncr006

runge = lambda x: RR(1/(1+x^2)) def equally_spaced_nodes(a,b,n_nodes): delta = (b-a)/n_nodes return [x.n() for x in srange(a,b+delta,delta)] 
       
equally_spaced_nodes(0,5,5) 
       
[0.000000000000000, 1.00000000000000, 2.00000000000000,
3.00000000000000, 4.00000000000000, 5.00000000000000]
[0.000000000000000, 1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000, 5.00000000000000]
def interpolating_polynomial(pts): R.<x> = PolynomialRing(RR) return R.lagrange_polynomial(pts) 
       
actual = plot(runge,-4.9,4.9,linestyle='--',color='green') pts = [(x, runge(x)) for x in equally_spaced_nodes(-5,5,5)] p1 = interpolating_polynomial(pts) P1 = plot(p1,-5,5,color='red') PTS = list_plot(pts) show(actual+PTS+P1) 
       

                                
                            

                                
plots = [plot(runge,-1.9,1.9,linestyle='--',color='green')] show(sum(plots)) for i in range(1,40,10): pts = [(x, runge(x)) for x in equally_spaced_nodes(-5,5,i)] p1 = interpolating_polynomial(pts) P1 = plot(p1,-4.9,4.9,color=colors[colors.keys()[i]]) plots.append(P1) show(sum(plots)) 
       

                                
                            

                                
def Chebyshev_nodes(a,b,n_nodes): # assuming a=-b return [b*cos(pi.n()*(2*i+1)/(2*n_nodes+2)).n() for i in range(n_nodes)] 
       
plots = [plot(runge,-4.9,4.9,linestyle='--',color='green')] show(sum(plots)) for i in range(1,40,10): pts = [(x, runge(x)) for x in Chebyshev_nodes(-5,5,i)] p1 = interpolating_polynomial(pts) P1 = plot(p1,-4.9,4.9,color=colors[colors.keys()[i]]) plots.append(P1) show(sum(plots)) 
       

                                
                            

                                
R = PolynomialRing(RR,'x') [x for x in R.divided_difference(zip([1,-1,2,-2,3,-3,4,-4],[1,1,2,3,5,8,13,21]))] 
       
[1, 0, 1/3, -1/12, 1/20, 1/240, -1/5040, -1/2520]
[1, 0, 1/3, -1/12, 1/20, 1/240, -1/5040, -1/2520]
 
       
[(1, 1), (-1, 1), (2, 2), (-2, 3), (3, 5), (-3, 8), (4, 13), (-4, 21)]
[(1, 1), (-1, 1), (2, 2), (-2, 3), (3, 5), (-3, 8), (4, 13), (-4, 21)]