Exercise 6.C.13

Answers

Proof. In this Exercise, I used the SymPy package from Python to calculate the integrals necessary for the Gram-Schmidt Procedure on the basis 1,x,x2,x3,x4,x5 of P5() and to compute the polynomial p with the formula in 6.55 (i). I found the following

p(x) = x5 (72765 8π8 + 693 8π6 + 654885 8π10 )+x3 (363825 4π8 315 4π4 + 39375 4π6 )+x (16065 8π4 + 105 8π2 + 155925 8π6 ) ,

which, if you assume π = 3.14159265359, is exactly what appers in 6.60. Here is the code used:

from sympy import * 
 
x = Symbol(’x’) 
 
def inner_product(f, g): 
   return integrate(f*g, (x, -pi, pi)) 
 
def gs_procedure(basis): 
   orthonormal_basis = [] 
 
   for j, v_j in enumerate(basis): 
       e_j = v_j - sum(map(lambda e_k: inner_product(v_j, e_k) * e_k, orthonormal_basis[:j - 1])) 
       e_j = e_j / sqrt(inner_product(e_j, e_j)) 
       orthonormal_basis.append(e_j) 
 
   return orthonormal_basis 
 
def project(func, orthonormal_basis): 
   return sum(map(lambda e_j: inner_product(func, e_j) * e_j, orthonormal_basis)) 
 
orthonormal_basis = gs_procedure([1, x, x**2, x**3, x**4, x**5]) 
 
approx_sin = project(sin(x), orthonormal_basis) 
 
p = collect(expand(approx_sin), x) 
print(latex(p))
User profile picture
2017-10-06 00:00
Comments