File Exchange

image thumbnail

quadvgk

version 1.0.0.0 (2.64 KB) by Adam Wyatt
G7-K15 adaptive quadrature on vector-valued functions

2 Downloads

Updated 18 Feb 2008

View License

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.

Comments and Ratings (5)

Dezhao

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?

Dezhao

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?

Andreas

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?

Andreas

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:

Example:
Y = @(x,n) 1./(bsxfun(@plus,(1:n)',x));
Qv = quadvgk(@(x) Y(x,10), [0;1], 10)

Andreas

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: quad_M;quadl_M

Inspired: NCTCDFVW