% Program to get the quadrature points
% and weight for Gauss-Legendre Quadrature
% Rule
clc
clear all
syms x
% Input n: Quad pt rule
n=14;
% Calculating the Pn(x)
% Legendre Polynomial
% Using recursive relationship
% P(order of polynomial, value of x)
% P(0,x)=1; P(1,x)=0;
% (i+1)*P(i+1,x)=(2*i+1)*x*P(i,x)-i*P(i-1,x)
m=n-1;
P0=1;
P1=x;
for i=1:1:m
Pn=((2.0*i+1)*x*P1-i*P0)/(i+1.0);
P0=P1;
P1=Pn;
end
if n==1
Pn=P1;
end
Pn=expand(Pn);
quadpts=solve(vpa(Pn,32));
quadpts=sort(quadpts);
% Finding the weights
% Formula for weights is given at
% http://mathworld.wolfram.com/Legendre-GaussQuadrature.html
% Equation (13)
for k=1:1:n
P0=1;
P1=x;
m=n;
% Calculating P(n+1,x)
for i=1:1:m
Pn=((2.0*i+1)*x*P1-i*P0)/(i+1.0);
P0=P1;
P1=Pn;
end
Pn=P1;
weights(k)=vpa(2*(1-quadpts(k)^2)/(n+1)^2/ …
subs(Pn,x,quadpts(k))^2,32);
end
fprintf(‘Quad point rule for n=%g \n’,n)
disp(‘ ‘)
disp(‘Abscissas’)
disp(quadpts)
disp(‘ ‘)
disp(‘Weights’)
disp(weights’)_______________________________________________________
Search
Blogroll
Web
Subscribe via reader
Subscribe via email
-
Blog Stats
- 300,607 hits
-
Top Posts
- How do I differentiate in MATLAB?
- How do I solve a nonlinear equation in MATLAB?
- How do I do spline interpolation in MATLAB?
- How do I read data from a textfile in MATLAB?
- How do I display the data of an array in MATLAB?
- MATLAB code for bubble sort
- A Matlab program for comparing Runge-Kutta methods
- Taylor series example
- How do I integrate a discrete function in MATLAB?
- How do I do polynomial interpolation in MATLAB
Pages
-
Recent Posts
Previous Posts
- February 2012 (1)
- January 2012 (2)
- December 2011 (2)
- November 2011 (2)
- September 2011 (2)
- August 2011 (2)
- July 2011 (2)
- June 2011 (3)
- May 2011 (2)
- April 2011 (2)
- March 2011 (3)
- February 2011 (2)
- January 2011 (3)
- December 2010 (1)
- October 2010 (1)
- September 2010 (1)
- August 2010 (1)
- July 2010 (1)
- June 2010 (1)
- May 2010 (1)
- April 2010 (2)
- March 2010 (1)
- February 2010 (2)
- January 2010 (1)
- November 2009 (3)
- October 2009 (3)
- September 2009 (2)
- August 2009 (3)
- July 2009 (2)
- June 2009 (2)
- May 2009 (2)
- April 2009 (3)
- March 2009 (4)
- February 2009 (3)
- January 2009 (3)
- November 2008 (4)
- October 2008 (3)
- September 2008 (4)
- August 2008 (6)
- July 2008 (13)
- June 2008 (14)
- May 2008 (2)
Tags
audiovisual lectures automatic integrator bubble sort buckling central divided difference chopping cofactor computational time decimal to binary conversion derivatives determinant Differentiation error floating point improper integral Integration Interpolation Introduction to Numerical Methods inverse error function least squares regression length of curves loops lotto LU Decomposition matlab MATLAB solve nonlinear equation nonlinear equations numerical integration Numerical Methods open courseware ordinary differential equation Ordinary Differential Equations programming Regression Round off error runge runge-kutta 2nd order method Simultaneous Linear Equations spline interpolation Taylor Series taylors theorem Trapezoidal rule truncation error video lectures of numerical methods
I wrote something similar, using mathematica instead, after watching your videos on applying the Gauss quadrature rules. I decided to offer the tabulated result on the page, too, in case it turns out to be useful for people who just want the quick values, with a download for the high precision numbers. Perhaps of interest, it’s up on http://processingjs.nihongoresources.com/bezierinfo/legendre-gauss-values.php (I used it as a resource for computing the arc length integral using legendre-gauss approximation, for http://processingjs.nihongoresources.com/bezierinf)
Thank you. This would be very useful to many people out there.