Numerical Integration: Three-term Gaussian Quadrature not giving correct answer

116 Views Asked by At

I'm using a 3 term Gaussian Quadrature method to integrate $\int^{1.3}_{0.75} (sin(x)-1)^2$

I have implemented this using Matlab/Octave through the following code:

%Three term Legendre root and co-efficients
x1 = 0.7745966692
x2 = 0.0000000000
x3 = -0.7745966692
c1 = 0.5555555556
c2 = 0.8888888889
c3 = 0.5555555556

%The integration interval is normalised to -1 to 1
function y = myFunc(x)
  y = (sin((0.55*x+2.05)/2) - 1)^2;
endfunction

approx_integral = c1*myFunc(x1) + c2*myFunc(x2) + c3*myFunc(x3)

The answer I get is 0.062249. This is far off the true analytical solution which is 0.017...

I have tried increasing the n-terms in the Gaussian Quadrature algorithm but this didn't improve accuracy. Any idea why my algorithm is incorrect?

2

There are 2 best solutions below

2
On BEST ANSWER

You are forgetting that the substitution $x=\frac{0.55x'+2.05}2$ leads to $dx=0.275dx'$ and you thus have to multiply your numerical result with $0.275$ to get your original, untransformed integral.

1
On

Hint:

Divide the limits of integration $(.75\rightarrow 1)$ and $(1\rightarrow 1.3)$ or more $$\int^{1}_{0.75} (\sin(x)-1)^2dx+\int^{1.3}_{1} (\sin(x)-1)^2dx$$