2

I'm new on Mathematica and I am an engeneer with only a little base of numerical computation. I have to integrate a trigonometrical function numerically with a Gauss integration. The function is:

   t[alpha_,x_]= ( 2 Sin[alpha]^4 - Cos[alpha]^2 Sin[alpha]^2 ) 1/(
 2 Sin[alpha]^4 (Cot[alpha]^2 - 1) (Cot[alpha]^2 - 
    0.5)) (-(1/(Cos[alpha]^2 Abs[x]^2)))

I have to integrate it in the interval from 0 to Pi. Then I have to find couples of points and weights like this

f = GaussianQuadratureWeights[n, 0, Pi]

with n the number of point and after add weight for the function t evaluated in the point?

    g = 0
For[ i = 1, i < n + 1, i++,

 g = g + f[[i, 2]] t[f[[i, 1]],x]
 ]
diana
  • 65
  • 6

1 Answers1

1
 g[a_] := ( 2 Sin[a]^4 - Cos[a]^2 Sin[a]^2 ) 1/(
   2 Sin[a]^4 (Cot[a]^2 - 1) (Cot[a]^2 - 0.5)) (-(1/(Cos[a]^2) ));

GaussLegendreQuadrature[a_, b_, n_, f_] := 
 Module[{weights, i}, weights = GaussianQuadratureWeights[n, -1, 1];
  (b - a)/2*Sum[weights[[i, 2]] f[(a + b)/2 + (b - a)/2 weights[[i, 1]]],{i,1, n}]]

GaussLegendreQuadrature[0, Pi, n, g]

Is it correct?

diana
  • 65
  • 6
  • You should check the geometry of that before you use any means of numerical integration. – bobbym Jul 05 '15 at 16:40
  • excuse my ignorance, what you mean for "check the geometry"? – diana Jul 05 '15 at 17:31
  • 1
    If you plot your function you will see that it goes vertical several times. According to Forman S. Acton numerical quadrature needs nice smooth functions. You will not get good results trying to numerically integrate that. – bobbym Jul 05 '15 at 18:28
  • If you FullSimplify that integrand and try to symbolically integrate you will get an interesting error message. Even Mathematica can not do the impossible. – bobbym Jul 05 '15 at 18:48