JuliaMath / Cubature.jl

One- and multi-dimensional adaptive integration routines for the Julia language
Other
127 stars 21 forks source link

passing parameters to function for integration? #30

Closed davidzentlermunro closed 7 years ago

davidzentlermunro commented 7 years ago

Is it possible to pass parameters to the function that will be integrated? For example if I am integrating Ae^x, and the value of A might change, can I do something like

function f(x,A)
    return Aexp^x
end
Avec=[1 2 3 4]
Res=ones(length(Avec))
for i in 1:length(Avec)
    Res[i]=pquadrature(f(Avec[i],x),xmin, xmax,reltol=1e-8, abstol=0, maxevals=0)
end

?

stevengj commented 7 years ago

Just define an anonymous function.

pquadrature(x -> f(Avec[i],x),xmin, xmax,reltol=1e-8, abstol=0, maxevals=0)