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;

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 Answers 2


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.

  • $\begingroup$ Good catch. Thanks alot! $\endgroup$
    – Dean P
    Apr 21, 2019 at 14:49
  • $\begingroup$ I see that you left out the $dx$ part in your formula. While it is only a formalism, it turns out that to include this is helpful in cases as such, as a reminder that somethine more needs to be done then 'only' doing the change of variable. $\endgroup$
    – Ingix
    Apr 21, 2019 at 14:55


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$$

  • $\begingroup$ No luck. I split the equation into 2 bounds as above and applied the same method in opening post and got 0.13... Increasing the quadrature terms to 5 yields 0.18. Both are far off the actual value of 0.017 $\endgroup$
    – Dean P
    Apr 21, 2019 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .