2
$\begingroup$

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]
 ]
$\endgroup$
2
  • $\begingroup$ Have you seen this? $\endgroup$ Commented Jul 5, 2015 at 15:09
  • $\begingroup$ no I haven't, thank you! So I have to write my function like this? (below) $\endgroup$
    – diana
    Commented Jul 5, 2015 at 16:22

1 Answer 1

1
$\begingroup$
 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?

$\endgroup$
4
  • $\begingroup$ You should check the geometry of that before you use any means of numerical integration. $\endgroup$
    – bobbym
    Commented Jul 5, 2015 at 16:40
  • $\begingroup$ excuse my ignorance, what you mean for "check the geometry"? $\endgroup$
    – diana
    Commented Jul 5, 2015 at 17:31
  • 1
    $\begingroup$ 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. $\endgroup$
    – bobbym
    Commented Jul 5, 2015 at 18:28
  • $\begingroup$ If you FullSimplify that integrand and try to symbolically integrate you will get an interesting error message. Even Mathematica can not do the impossible. $\endgroup$
    – bobbym
    Commented Jul 5, 2015 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.