Main Content

Gauss-Laguerre Quadrature Evaluation Points and Weights

This example shows how to solve polynomial equations and systems of equations, and work with the results using Symbolic Math Toolbox™.

Gaussian quadrature rules approximate an integral by sums a b f ( t ) w ( t ) d t i = 1 n f ( x i ) α i . Here, the x i and α i are parameters of the method, depending on n but not on f . They follow from the choice of the weight function w ( t ) , as follows. Associated to the weight function is a family of orthogonal polynomials. The polynomials' roots are the evaluation points x i . Finally, the weights α i are determined by the condition that the method be correct for polynomials of small degree. Consider the weight function w ( t ) = exp ( - t ) on the interval [ 0 , ] . This case is known as Gauss-Laguerre quadrature.

symstn = 4; w(t) = exp(-t);

Assume you know the first n members of the family of orthogonal polynomials. In case of the quadrature rule considered here, they turn out to be the Laguerre polynomials.

F = laguerreL(0:n-1, t)
F =

( 1 1 - t t 2 2 - 2 t + 1 - t 3 6 + 3 t 2 2 - 3 t + 1 )

LetLbe the n + 1 st polynomial, the coefficients of which are still to be determined.

X = sym('X', [1, n+1])
X =
                 
                  
                   
                    
                     (
                    
                     
                      
                       
                        
                         
                          
                           X
                         
                         
                          
                           1
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           X
                         
                         
                          
                           2
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           X
                         
                         
                          
                           3
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           X
                         
                         
                          
                           4
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           X
                         
                         
                          
                           5
                         
                        
                       
                      
                     
                    
                    
                     )
                   
                  
                 
L = poly2sym(X, t)
L =
                 
                  
                   
                    
                     
                      
                       
                        
                         
                          X
                        
                        
                         
                          1
                        
                       
                       
                       
                       
                        
                         
                          t
                        
                        
                         
                          4
                        
                       
                      
                     
                     
                      +
                     
                      
                       
                        
                         
                          X
                        
                        
                         
                          2
                        
                       
                       
                       
                       
                        
                         
                          t
                        
                        
                         
                          3
                        
                       
                      
                     
                     
                      +
                     
                      
                       
                        
                         
                          X
                        
                        
                         
                          3
                        
                       
                       
                       
                       
                        
                         
                          t
                        
                        
                         
                          2
                        
                       
                      
                     
                     
                      +
                     
                      
                       
                        
                         
                          X
                        
                        
                         
                          4
                        
                       
                       
                       
                       
                        t
                      
                     
                     
                      +
                     
                      
                       
                        X
                      
                      
                       
                        5
                      
                     
                    
                   
                  
                 

Represent the orthogonality relations between the Laguerre polynomialsFandLin a system of equationssys.

sys = [int(F.*L.*w(t), t, 0, inf) == 0]
sys =
                 
                  
                   
                    
                     (
                    
                     
                      
                       
                        
                         
                          
                           
                            
                             
                              
                               24
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               6
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               2
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               X
                             
                             
                              
                               4
                             
                            
                            
                             +
                            
                             
                              
                               X
                             
                             
                              
                               5
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           
                            
                             -
                            
                             
                              
                               96
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               18
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               4
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               X
                             
                             
                              
                               4
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           
                            
                             
                              
                               144
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               18
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               2
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           
                            
                             -
                            
                             
                              
                               96
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               6
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                     
                    
                    
                     )
                   
                  
                 

Add the condition that the polynomial have norm 1.

sys = [sys, int(L^2.*w(t), 0, inf) == 1]
sys =
                 
                  
                   
                    
                     (
                    
                     
                      
                       
                        
                         
                          
                           
                            
                             
                              
                               24
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               6
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               2
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               X
                             
                             
                              
                               4
                             
                            
                            
                             +
                            
                             
                              
                               X
                             
                             
                              
                               5
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           
                            
                             -
                            
                             
                              
                               96
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               18
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               4
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               X
                             
                             
                              
                               4
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           
                            
                             
                              
                               144
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               18
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               2
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           
                            
                             -
                            
                             
                              
                               96
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                             
                            
                            
                             -
                            
                             
                              
                               6
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                           
                          
                          
                           =
                          
                           0
                         
                        
                       
                      
                      
                       
                        
                         
                          
                           
                            
                             
                              
                               40320
                              
                              
                              
                               
                                
                                 
                                  
                                   X
                                 
                                 
                                  
                                   1
                                 
                                
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               10080
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               1440
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               240
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 4
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               48
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 1
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 5
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               720
                              
                              
                              
                               
                                
                                 
                                  
                                   X
                                 
                                 
                                  
                                   2
                                 
                                
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               240
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               48
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 4
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               12
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 2
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 5
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               24
                              
                              
                              
                               
                                
                                 
                                  
                                   X
                                 
                                 
                                  
                                   3
                                 
                                
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               12
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 4
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               4
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 3
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 5
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               2
                              
                              
                              
                               
                                
                                 
                                  
                                   X
                                 
                                 
                                  
                                   4
                                 
                                
                               
                               
                                
                                 2
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               2
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 4
                               
                              
                              
                              
                              
                               
                                
                                 X
                               
                               
                                
                                 5
                               
                              
                             
                            
                            
                             +
                            
                             
                              
                               
                                
                                 X
                               
                               
                                
                                 5
                               
                              
                             
                             
                              
                               2
                             
                            
                           
                          
                          
                           =
                          
                           1
                         
                        
                       
                      
                     
                    
                    
                     )
                   
                  
                 

Solve for the coefficients ofL.

S = solve(sys, X)
S =结构体字段:X1: [2x1 sym] X2: [2x1 sym] X3: [2x1 sym] X4: [2x1 sym] X5: [2x1 sym]

solvereturns the two solutions in a structure array. Display the solutions.

structfun(@display, S)
ans =

( - 1 24 1 24 )

ans =

( 2 3 - 2 3 )

ans =

( - 3 3 )

ans =

( 4 - 4 )

ans =

( - 1 1 )

Make the solution unique by imposing an extra condition that the first coefficient be positive:

sys = [sys, X(1)>0]; S = solve(sys, X)
S =结构体字段:X1: 1/24 X2: -2/3 X3: 3 X4: -4 X5: 1

Substitute the solution intoL.

L = subs(L, S)
L =

t 4 24 - 2 t 3 3 + 3 t 2 - 4 t + 1

As expected, this polynomial is the |n|th Laguerre polynomial:

laguerreL(n, t)
ans =

t 4 24 - 2 t 3 3 + 3 t 2 - 4 t + 1

The evaluation points x i are the roots of the polynomialL. SolveLfor the evaluation points. The roots are expressed in terms of therootfunction.

x = solve(L)
x =

( root ( σ 1 , z , 1 ) root ( σ 1 , z , 2 ) root ( σ 1 , z , 3 ) root ( σ 1 , z , 4 ) ) where σ 1 = z 4 - 16 z 3 + 72 z 2 - 96 z + 24

The form of the solutions might suggest that nothing has been achieved, but various operations are available on them. Compute floating-point approximations usingvpa:

vpa(x)
ans =

( 0.32254768961939231180036145910437 1.7457611011583465756868167125179 4.5366202969211279832792853849571 9.3950709123011331292335364434205 )

Some spurious imaginary parts might occur. Prove symbolically that the roots are real numbers:

isAlways(in(x,'real'))
ans =4x1 logical array1 1 1 1

For polynomials of degree less than or equal to 4, you can useMaxDegreeto obtain the solutions in terms of nested radicals instead in terms ofroot. However, subsequent operations on results of this form would be slow.

xradical = solve(L,'MaxDegree', 4)
xradical =

( 4 - σ 1 - σ 3 4 + σ 1 - σ 3 σ 3 - σ 2 + 4 σ 3 + σ 2 + 4 ) where σ 1 = 96 σ 6 σ 4 - 3 σ 5 σ 4 - 288 σ 4 - 512 3 6 6 + 3 6 i 2 768 + 128 3 6 i 1 / 6 144 σ 6 + 9 σ 5 + 864 1 / 4 σ 2 = 96 σ 6 σ 4 - 3 σ 5 σ 4 - 288 σ 4 + 512 3 6 6 + 3 6 i 2 768 + 128 3 6 i 1 / 6 144 σ 6 + 9 σ 5 + 864 1 / 4 σ 3 = σ 4 2 768 + 128 3 6 i 1 / 6 σ 4 = 16 σ 6 + σ 5 + 96 σ 5 = 768 + 128 3 6 i 2 / 3 σ 6 = 768 + 128 3 6 i 1 / 3

The weights α i are given by the condition that for polynomials of degree less than n , the quadrature rule must produce exact results. It is sufficient if this holds for a basis of the vector space of these polynomials. This condition results in a system of four equations in four variables.

y = sym('y', [n, 1]); sys = sym(zeros(n));fork=0:n-1 sys(k+1) = sum(y.*(x.^k)) == int(t^k * w(t), t, 0, inf);endsys
sys =

( y 1 + y 2 + y 3 + y 4 = 1 0 0 0 y 1 root ( σ 1 , z , 1 ) + y 2 root ( σ 1 , z , 2 ) + y 3 root ( σ 1 , z , 3 ) + y 4 root ( σ 1 , z , 4 ) = 1 0 0 0 y 1 root ( σ 1 , z , 1 ) 2 + y 2 root ( σ 1 , z , 2 ) 2 + y 3 root ( σ 1 , z , 3 ) 2 + y 4 root ( σ 1 , z , 4 ) 2 = 2 0 0 0 y 1 root ( σ 1 , z , 1 ) 3 + y 2 root ( σ 1 , z , 2 ) 3 + y 3 root ( σ 1 , z , 3 ) 3 + y 4 root ( σ 1 , z , 4 ) 3 = 6 0 0 0 ) where σ 1 = z 4 - 16 z 3 + 72 z 2 - 96 z + 24

Solve the system both numerically and symbolically. The solution is the desired vector of weights α i .

[a1, a2, a3, a4] = vpasolve(sys, y)
a1 =
                 
                  
                   
                    0.60315410434163360163596602381808
                  
                 
a2 =
                 
                  
                   
                    0.35741869243779968664149201745809
                  
                 
a3 =
                 
                  
                   
                    0.03888790851500538427243816815621
                  
                 
a4 =
                 
                  
                   
                    0.00053929470556132745010379056762059
                  
                 
[alpha1, alpha2, alpha3, alpha4] = solve(sys, y)
alpha1 =

- σ 3 σ 2 + σ 3 σ 1 + σ 2 σ 1 - σ 3 σ 2 σ 1 - 2 σ 3 - 2 σ 2 - 2 σ 1 + 6 σ 4 - σ 3 σ 4 σ 2 + σ 4 σ 1 - σ 2 σ 1 - σ 4 2 where σ 1 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 4 ) σ 2 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 3 ) σ 3 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 2 ) σ 4 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 1 )

alpha2 =

root ( σ 1 , z , 1 ) root ( σ 1 , z , 3 ) + root ( σ 1 , z , 1 ) root ( σ 1 , z , 4 ) + root ( σ 1 , z , 3 ) root ( σ 1 , z , 4 ) - root ( σ 1 , z , 1 ) root ( σ 1 , z , 3 ) root ( σ 1 , z , 4 ) - 2 root ( σ 1 , z , 1 ) - 2 root ( σ 1 , z , 3 ) - 2 root ( σ 1 , z , 4 ) + 6 root ( σ 1 , z , 2 ) - root ( σ 1 , z , 1 ) root ( σ 1 , z , 2 ) - root ( σ 1 , z , 3 ) root ( σ 1 , z , 2 ) - root ( σ 1 , z , 4 ) where σ 1 = z 4 - 16 z 3 + 72 z 2 - 96 z + 24

alpha3 =

σ 3 σ 2 + σ 3 σ 1 + σ 2 σ 1 - σ 3 σ 2 σ 1 - 2 σ 3 - 2 σ 2 - 2 σ 1 + 6 σ 4 - σ 1 σ 3 σ 2 - σ 3 σ 4 - σ 2 σ 4 + σ 4 2 where σ 1 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 4 ) σ 2 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 2 ) σ 3 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 1 ) σ 4 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 3 )

alpha4 =

- σ 3 σ 2 + σ 3 σ 1 + σ 2 σ 1 - σ 3 σ 2 σ 1 - 2 σ 3 - 2 σ 2 - 2 σ 1 + 6 σ 4 2 σ 3 + σ 4 2 σ 2 + σ 4 2 σ 1 - σ 4 3 + σ 3 σ 2 σ 1 - σ 3 σ 2 σ 4 - σ 3 σ 1 σ 4 - σ 2 σ 1 σ 4 where σ 1 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 3 ) σ 2 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 2 ) σ 3 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 1 ) σ 4 = root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 4 )

Alternatively, you can also obtain the solution as a structure by giving only one output argument.

S = solve(sys, y)
S =结构体字段:y1: -(root(z^4 - 16*z^3 + 72*z^2 - 96*z + 24, z, 2)*root(z^4 - 16*z^3... y2: (root(z^4 - 16*z^3 + 72*z^2 - 96*z + 24, z, 1)*root(z^4 - 16*z^3 ... y3: (root(z^4 - 16*z^3 + 72*z^2 - 96*z + 24, z, 1)*root(z^4 - 16*z^3 ... y4: -(root(z^4 - 16*z^3 + 72*z^2 - 96*z + 24, z, 1)*root(z^4 - 16*z^3...
structfun(@double, S)
ans =4×10.6032 0.3574 0.0389 0.0005

Convert the structureSto a symbolic array:

Scell = struct2cell(年代);alpha = transpose([Scell{:}])
alpha =

( - σ 3 + σ 15 + σ 2 - σ 6 - σ 12 - σ 11 - σ 10 + 6 root ( σ 16 , z , 1 ) - root ( σ 16 , z , 2 ) σ 1 + σ 4 - σ 2 - root ( σ 16 , z , 1 ) 2 σ 1 + σ 4 + σ 2 - σ 7 - σ 13 - σ 11 - σ 10 + 6 root ( σ 16 , z , 2 ) - root ( σ 16 , z , 1 ) root ( σ 16 , z , 2 ) - root ( σ 16 , z , 3 ) root ( σ 16 , z , 2 ) - root ( σ 16 , z , 4 ) σ 5 + σ 4 + σ 15 - σ 8 - σ 13 - σ 12 - σ 10 + 6 root ( σ 16 , z , 3 ) - root ( σ 16 , z , 4 ) σ 5 - σ 1 - σ 3 + root ( σ 16 , z , 3 ) 2 - σ 5 + σ 1 + σ 3 - σ 9 - σ 13 - σ 12 - σ 11 + 6 σ 14 root ( σ 16 , z , 1 ) + σ 14 root ( σ 16 , z , 2 ) + σ 14 root ( σ 16 , z , 3 ) - root ( σ 16 , z , 4 ) 3 + σ 9 - σ 8 - σ 7 - σ 6 ) where σ 1 = root ( σ 16 , z , 1 ) root ( σ 16 , z , 3 ) σ 2 = root ( σ 16 , z , 3 ) root ( σ 16 , z , 4 ) σ 3 = root ( σ 16 , z , 2 ) root ( σ 16 , z , 3 ) σ 4 = root ( σ 16 , z , 1 ) root ( σ 16 , z , 4 ) σ 5 = root ( σ 16 , z , 1 ) root ( σ 16 , z , 2 ) σ 6 = root ( σ 16 , z , 2 ) root ( σ 16 , z , 3 ) root ( σ 16 , z , 4 ) σ 7 = root ( σ 16 , z , 1 ) root ( σ 16 , z , 3 ) root ( σ 16 , z , 4 ) σ 8 = root ( σ 16 , z , 1 ) root ( σ 16 , z , 2 ) root ( σ 16 , z , 4 ) σ 9 = root ( σ 16 , z , 1 ) root ( σ 16 , z , 2 ) root ( σ 16 , z , 3 ) σ 10 = 2 root ( σ 16 , z , 4 ) σ 11 = 2 root ( σ 16 , z , 3 ) σ 12 = 2 root ( σ 16 , z , 2 ) σ 13 = 2 root ( σ 16 , z , 1 ) σ 14 = root ( σ 16 , z , 4 ) 2 σ 15 = root ( σ 16 , z , 2 ) root ( σ 16 , z , 4 ) σ 16 = z 4 - 16 z 3 + 72 z 2 - 96 z + 24

The symbolic solution looks complicated. Simplify it, and convert it into a floating point vector:

alpha = simplify(alpha)
alpha =

( root ( σ 1 , z , 1 ) 2 72 - 29 root ( σ 1 , z , 1 ) 144 + 2 3 root ( σ 1 , z , 2 ) 2 72 - 29 root ( σ 1 , z , 2 ) 144 + 2 3 root ( σ 1 , z , 3 ) 2 72 - 29 root ( σ 1 , z , 3 ) 144 + 2 3 root ( σ 1 , z , 4 ) 2 72 - 29 root ( σ 1 , z , 4 ) 144 + 2 3 ) where σ 1 = z 4 - 16 z 3 + 72 z 2 - 96 z + 24

vpa(alpha)
ans =

( 0.60315410434163360163596602381808 0.35741869243779968664149201745809 0.03888790851500538427243816815621 0.00053929470556132745010379056762059 )

Increase the readability by replacing the occurrences of the rootsxinalphaby abbreviations:

subs(alpha, x, sym('R', [4, 1]))
ans =

( R 1 2 72 - 29 R 1 144 + 2 3 R 2 2 72 - 29 R 2 144 + 2 3 R 3 2 72 - 29 R 3 144 + 2 3 R 4 2 72 - 29 R 4 144 + 2 3 )

总和the weights to show that their sum equals 1:

simplify(sum(alpha))
ans =
                 
                  
                   
                    1
                  
                 

A different method to obtain the weights of a quadrature rule is to compute them using the formula α i = a b w ( t ) j i t - x j x i - x j d t . Do this for i = 1 . It leads to the same result as the other method:

int(w(t) * prod((t - x(2:4)) ./ (x(1) - x(2:4))), t, 0, inf)
ans =

root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 1 ) 2 72 - 29 root ( z 4 - 16 z 3 + 72 z 2 - 96 z + 24 , z , 1 ) 144 + 2 3

The quadrature rule produces exact results even for all polynomials of degree less than or equal to 2 n - 1 , but not for t 2 n .

simplify(sum(alpha.*(x.^(2*n-1))) -int(t^(2*n-1)*w(t), t, 0, inf))
ans =
                 
                  
                   
                    0
                  
                 
simplify(sum(alpha.*(x.^(2*n))) -int(t^(2*n)*w(t), t, 0, inf))
ans =
                 
                  
                   
                    
                     
                      -
                     
                      576
                    
                   
                  
                 

Apply the quadrature rule to the cosine, and compare with the exact result:

vpa(总和(α。* (cos (x))))
ans =
                 
                  
                   
                    0.50249370546067059229918484198931
                  
                 
int(cos(t)*w(t), t, 0, inf)
ans =

1 2

For powers of the cosine, the error oscillates between odd and even powers:

errors = zeros(1, 20);fork=1:20 errors(k) = double(sum(alpha.*(cos(x).^k)) -int(cos(t)^k*w(t), t, 0, inf));endplot(real(errors))

Figure contains an axes object. The axes object contains an object of type line.