Adaptation of quadgk for use on vector valued functions (i.e. the integral of many functions).
The input function should return a matrix of size (NF, NX) where NF is the number of integrals to calculate and NX is the number of points across each function.
This routine is as efficient as quadgk on a single function, more efficient on calculating multiple functions across the same span (provided they require similar sampling).
Consider the following problem:
E(x, L) = int(z = 0..L, fft(E(kx).*exp(i*kx.^2*z/2k)));
quadvgk allows E(kx) to be evaluated once only for every z position, thus significantly improving performance.
Adam Wyatt (2020). quadvgk (https://www.mathworks.com/matlabcentral/fileexchange/18801-quadvgk), MATLAB Central File Exchange. Retrieved .
Hey Andreas, I solved my previous problem. However, I found the quadvgk is lower than using loops.
To make it work I used bsxfun and repmat. I think it is bsxfun and repmat that spent a lot of time. What's your opinion?
Hey Andreas, this is what I am searching for.
I runned your package with 'bsxfun'. When the vector is small (or the number of n in your example) it is OK. However when the vector is huge(let's say n>>100) the program ran out of memory. Is there a way to fix it?
Sometimes it becomes really slow (and even though it only occurs on occasion, there many, many occasions in my m-files makes it an issue). Any idea anyone?
This one worked like a charm for a couple of integrals where quadv failed (and iterating over quadgk was too slow).
The file doesn't work if you follow the example though. It should be something like:
Y = @(x,n) 1./(bsxfun(@plus,(1:n)',x));
Qv = quadvgk(@(x) Y(x,10), [0;1], 10)