Numerical integration/Gauss-Legendre Quadrature: Difference between revisions
Numerical integration/Gauss-Legendre Quadrature (view source)
Revision as of 01:42, 25 January 2021
, 3 years ago→{{header|J}}: Use more descriptive names and tacit
(→{{header|J}}: Use more descriptive names and tacit) |
|||
Line 823:
=={{header|J}}==
'''Solution:'''
<lang j>
getLegendreCoeffs=: verb define M.
(%~ <:@(,~ +:) -/@:* (0;'') ,&> [: getLegendreCoeffs&.> -&1 2) y
)
getPolyRoots=: 1 {:: p. NB. returns the roots of a polynomial
getGaussLegendreWeights=: 2 % -.@*:@[ * (*:@p.~ p..) NB. form: roots getGaussLegendreWeights coeffs
getGaussLegendrePoints=: (getPolyRoots ([ ,: getGaussLegendreWeights) ])@getLegendreCoeffs
NB.*integrateGaussLegendre a Integrates a function u with a n-point Gauss-Legendre quadrature rule over the interval [a,b]
NB. form: npoints function integrateGaussLegendre (a,b)
integrateGaussLegendre=: adverb define
:
)</lang>
{{out|Example use}}
<lang j> 5 ^
20.0356
-~/ ^ _3 3 NB. true value
20.0357</lang>
=={{header|Java}}==
|