Ian Jauslin
summaryrefslogtreecommitdiff
blob: 0ad456adcf653cffcc4b0e177d2146105da95197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# approximate \int_a^b f using Gauss-Legendre quadratures
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
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
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