Question: Write a MATLAB function to implement the composite Gauss quadrature. The input is(f, a, b, m ,n)wheref, a, b, mhave the same meaning as in

Write a MATLAB function to implement the composite Gauss quadrature. The input is(f, a, b, m ,n)wheref, a, b, mhave the same meaning as in problem 3, andnis the degree of the interpolating polyno-mial in each subinterval. Use the gauss.m file on Canvas to generate the nodes and weights for the Gaussquadrature. Usen= 2

to do part (a).

Write a MATLAB function to implement the composite Gauss quadrature. The input

What order of accuracy do you observe?

Now do (b),

is(f, a, b, m ,n)wheref, a, b, mhave the same meaning as

now what are the digits that you believe are correct?

Code for the gauss.m file mentioned in the problem:

function [x,w]=gauss(a,b,N)

% gauss.m

%

% This script is for computing definite integrals using Legendre-Gauss

% Quadrature. Computes the Legendre-Gauss nodes and weights on an

interval

% [a,b] with truncation order N

%

% Suppose you have a continuous function f(x) which is defined on [a,b]

% which you can evaluate at any x in [a,b]. Simply evaluate it at all of

% the values contained in the x vector to obtain a vector f. Then compute

% the definite integral using sum(f.*w);

%

% Written by Greg von Winckel - 02/25/2004

N=N-1;

N1=N+1; N2=N+2;

xu=linspace(-1,1,N1)';

% Initial guess

y=cos((2*(0:N)'+1)*pi/(2*N+2))+(0.27/N1)*sin(pi*xu*N/N2);

% Legendre-Gauss Vandermonde Matrix

L=zeros(N1,N2);

% Derivative of LGVM

Lp=zeros(N1,N2);

% Compute the zeros of the N+1 Legendre Polynomial

% using the recursion relation and the Newton-Raphson method

y0=2;

% Iterate until new points are uniformly within epsilon of old points

while max(abs(y-y0))>eps

L(:,1)=1;

Lp(:,1)=0;

L(:,2)=y;

Lp(:,2)=1;

for k=2:N1

L(:,k+1)=( (2*k-1)*y.*L(:,k)-(k-1)*L(:,k-1) )/k;

end

Lp=(N2)*( L(:,N1)-y.*L(:,N2) )./(1-y.^2);

y0=y;

y=y0-L(:,N2)./Lp;

end

% Linear map from[-1,1] to [a,b]

x=(a*(1-y)+b*(1+y))/2;

% Compute the weights

w=(b-a)./((1-y.^2).*Lp.^2)*(N2/N1)^2;

(a) Test your code on J 2 xe-rcos2rdz 3(e-2x 1) 10??2 Use a for loop to calculate the error for m = 2, 22, 23, . . . , 28 and empirically calculate the order of accuracy. Put m, the error and the order as columns in a matrix and display your results. (a) Test your code on J 2 xe-rcos2rdz 3(e-2x 1) 10??2 Use a for loop to calculate the error for m = 2, 22, 23, . . . , 28 and empirically calculate the order of accuracy. Put m, the error and the order as columns in a matrix and display your results

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!