Quadgk integration

Hello, I’ve got a function I’m trying to integrate, it’s a single variable for a position in space (an electric potential at that point). I’d like to pass my function a position, and have it evaluate the integral at that point in space. So far it works like so.

function unknotintegralfunction(a,b,c,t)
1/(sqrt(square(a-unknotx(t))+square(b-unknot(t))+square(c)))
end

It basically calculates the distance at a point a,b,c from a paramaterized function which has the variable t. I then pass the function above to an integration function

function unknotpotential(a,b,c)
ans = quadgk(unknotintegralfunction(a,b,c),0,2*pi,order=quadorder)
end

Which I had hoped would integrate over my function for t from 0->2pi. In python I could do something like this with lambda, but I’m not too sure how to accomplish this in Julia. Any advice would be appreciated!

you need

function unknotpotential(a,b,c)
ans = quadgk(t->unknotintegralfunction(a,b,c,t),0,2*pi,order=quadorder)
end

(untested)

Also it looks like you are missing a definition for quadorder

2 Likes

Thank you! I’m getting some different errors now, I need to look in to if I’ve set some array values correctly, but progress is progress! I should have mentioned that I’d defined quadorder earlier on in my code.