I’m trying to integrate the following formula. It computes an electric potential at a point from a circular ring of charge.
\phi=\int_0^{2\pi} \frac{1}{\sqrt{(x-cos(t))^2+(y-sin(t))^2+z^2)}}dt
I’ve implemented the function itself like so.
function unknotintegralfunction(a,b,c,t)
1/(sqrt(((a.-cos.(t))^2).+((b.-sin.(t))^2).+c^2)) #using .math means element wise
end
And the integration like so, note that quadorder is set to 1000 currently.
function unknotpotential(a,b,c)
ans = quadgk(t->unknotintegralfunction(a,b,c,t),0,2*pi,order=quadorder)
# we'll use the default errors to start
end
Passing a test point at 2,2,2 generates the following LAPACK error
LinearAlgebra.LAPACKException(462)
chklapackerror@lapack.jl:38[inlined]
stev!@lapack.jl:3749[inlined]
eigvals!(::LinearAlgebra.SymTridiagonal{Float64,Array{Float64,1}})@tridiag.jl:292
eigvals(::LinearAlgebra.SymTridiagonal{Float64,Array{Float64,1}})@tridiag.jl:293
eignewt(::Array{Float64,1}, ::Int64, ::Int64)@gausskronrod.jl:44
kronrod(::Type{Float64}, ::Int64)@gausskronrod.jl:193
macro expansion@gausskronrod.jl:257[inlined]
cachedrule@gausskronrod.jl:257[inlined]
do_quadgk(::Main.workspace332.var"#1#2"{Int64,Int64,Int64}, ::Tuple{Float64,Float64}, ::Int64, ::Nothing, ::Nothing, ::Int64, ::typeof(LinearAlgebra.norm))@adapt.jl:7
(::QuadGK.var"#28#29"{Nothing,Nothing,Int64,Int64,typeof(LinearAlgebra.norm)})(::Function, ::Tuple{Float64,Float64}, ::Function)@adapt.jl:179
handle_infinities@adapt.jl:113[inlined]
#quadgk#27@adapt.jl:177[inlined]
#quadgk#26@adapt.jl:173[inlined]
unknotpotential(::Int64, ::Int64, ::Int64)@Other: 2
top-level scope@Local: 1[inlined]
I’m way out of my depth with this and I’m not too sure where I’m going wrong. Is the quadrature method that I’m using incorrect for the type of function I’m trying to integrate? Or is it something else I’ve done wrong?