Home > K25104 > Integration > gauss_legendre_rule_script.m

gauss_legendre_rule_script

PURPOSE ^

Usage example for gauss_legendre_rule

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Usage example for gauss_legendre_rule
 related to Exercies 5.3

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Usage example for gauss_legendre_rule
0002 % related to Exercies 5.3
0003 
0004 a = -1;
0005 b= 1;
0006 E = zeros(10,4);
0007 for n=2:5
0008     for j = 1:10
0009         syms x;
0010         f = x^j;
0011         I = int(f,x,a,b); % true value of the integral
0012         f = matlabFunction(f);
0013         [ Q ] = gauss_legendre_rule( f,a,b,n ); % approximation of the integral
0014         E(j,n-1) = Q-I;
0015     end
0016 end
0017 disp('The difference between the Gauss-Legendre rule (n=2,3,4,5) and the true value integrating x^j, j=1,...10 is');
0018 format shortE;
0019 E

Generated on Mon 18-Jan-2016 10:25:49 by m2html © 2005