Reputation: 401
I'm using "integral" subroutine in MATLAB to evaluate some integrals. We know that "integral" is based on an adaptive quadrature rule.
Is it possible and how to return number of function evaluations in "integral"?
Upvotes: 1
Views: 588
Reputation: 2822
YES!
I just unfortunately had to do this to compare a MATLAB to Python implementation. Say your MATLAB function is:
function value = integrand(x, flag, F,K,vol,T2,T1)
value = (log(x ./ (x+K)) + 0.5 .* (vol.^2) .* (T2-T1)) ./ (vol .* sqrt(T2 - T1));end
And your call to the function is:
quadgk(@(x) integrand(x, flag, F, K, vol, T2, T1), -K, Inf, 'AbsTol',tolerance);
Put a breakpoint at the function entry point (by clicking on the left of the function, value
in this example), run the function with its inputs, and then click on the x
variable in the workspace and it will show you the size which equals the number of integration points in the function. It also gives you the values passed during the integration.
Upvotes: 0