Anonymous user
Numerical integration/Gauss-Legendre Quadrature: Difference between revisions
Numerical integration/Gauss-Legendre Quadrature (view source)
Revision as of 05:46, 11 June 2011
, 12 years agoGP
(added Ursala) |
(GP) |
||
Line 141:
(int #'(lambda (x) x) 5 0 6000)
1.8000000000000004d7</lang>
=={{header|PARI/GP}}==
This task is easy in GP thanks to built-in support for Legendre polynomials and efficient (Schonhage-Gourdon) polynomial root finding.
<lang parigp>GLq(f,a,b,n)={
my(P=pollegendre(n),Pp=P',x=polroots(P));
(b-a)*sum(i=1,n,f((b-a)*x[i]/2+(a+b)/2)/(1-x[i]^2)/subst(Pp,'x,x[i])^2)
};
# \\ Turn on timer
GLq(x->exp(x), -3, 3, 5)</lang>
Results:
<pre>time = 0 ms.
%1 = 20.035577718385562153928535725275093932 + 0.E-37*I</pre>
=={{header|Tcl}}==
|