calculate legendre-gauss-radau points and weights in matlab in matlab

Legendre-Gauss-Radau quadrature is used to numerically integrate a function over a finite interval from -1 to 1. It involves calculating the Legendre-Gauss-Radau points and weights based on the specified number of nodes. In Matlab, we can use the lgwt function to calculate the Legendre-Gauss-Radau points and weights.

main.m
function [x,w]=lgwt(N,a,b)

% N : number of nodes
% a : left endpoint of the interval
% b : right endpoint of the interval

% Initialization
x=zeros(N,1);
w=zeros(N,1);

% Calculation of Legendre-Gauss-Radau points and weights
for n=1:N
    if n==1
        x(n)=b;
        w(n)=2/(a-b);
    else
        i=n-1;
        p=legendreP(i,0);
        x(n)=b-(1/(a-b))*((1-p)/(2*i+1));
        w(n)=2/((a-b)*((1-x(n))^2)*p^2);
    end
end
432 chars
23 lines

We can call this function and provide the necessary inputs to compute the Legendre-Gauss-Radau points and weights. For example, to compute the LG-R points and weights with 3 nodes over the interval [-1,1], we can run the following:

main.m
>> [x,w] = lgwt(3,-1,1)

x =

   -1
   -0.4472
    1.0000

w =

    0.3333
    1.4667
    0.2000
97 chars
14 lines

This will return the 3 Legendre-Gauss-Radau points and the corresponding weights.

gistlibby LogSnag