diff options
author | Ian Jauslin <ian@jauslin.org> | 2021-10-04 11:12:34 -0400 |
---|---|---|
committer | Ian Jauslin <ian@jauslin.org> | 2021-10-04 11:22:07 -0400 |
commit | e72af82c3ed16b81cdb5043c58abbdbb3cf02102 (patch) | |
tree | 2d2a4bf7a7e4be1e1d69dce37ff5ff37a83ff375 /src/integration.jl |
Initial commitv0.3
Diffstat (limited to 'src/integration.jl')
-rw-r--r-- | src/integration.jl | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/integration.jl b/src/integration.jl new file mode 100644 index 0000000..9be4641 --- /dev/null +++ b/src/integration.jl @@ -0,0 +1,58 @@ +## Copyright 2021 Ian Jauslin +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. + +# approximate \int_a^b f using Gauss-Legendre quadratures +@everywhere function integrate_legendre(f,a,b,weights) + out=0 + for i in 1:length(weights[1]) + out+=(b-a)/2*weights[2][i]*f((b-a)/2*weights[1][i]+(b+a)/2) + end + return out +end +# \int f*g where g is sampled at the Legendre nodes +@everywhere function integrate_legendre_sampled(f,g,a,b,weights) + out=0 + for i in 1:length(weights[1]) + out+=(b-a)/2*weights[2][i]*f((b-a)/2*weights[1][i]+(b+a)/2)*g[i] + end + return out +end + + +# approximate \int_a^b f/sqrt((b-x)(x-a)) using Gauss-Chebyshev quadratures +@everywhere function integrate_chebyshev(f,a,b,N) + out=0 + for i in 1:N + out=out+pi/N*f((b-a)/2*cos((2*i-1)/(2*N)*pi)+(b+a)/2) + end + return out +end + +# approximate \int_0^\infty dr f(r)*exp(-a*r) using Gauss-Chebyshev quadratures +@everywhere function integrate_laguerre(f,a,weights_gL) + out=0. + for i in 1:length(weights_gL[1]) + out+=1/a*f(weights_gL[1][i]/a)*weights_gL[2][i] + end + return out +end + +# Hann window +@everywhere function hann(x,L) + if abs(x)<L/2 + return cos(pi*x/L)^2 + else + return 0. + end +end |