Code covered by the BSD License  

Highlights from
quadvgk

4.5

4.5 | 3 ratings Rate this file 6 Downloads (last 30 days) File Size: 2.64 KB File ID: #18801

quadvgk

by Adam Wyatt

 

18 Feb 2008 (Updated 18 Feb 2008)

G7-K15 adaptive quadrature on vector-valued functions

| Watch this File

File Information
Description

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.

Acknowledgements

Quad M;Quadl M inspired this file.

This file inspired Nctcdfvw.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
apative, functions, integration(2), quadrature(3), valued(3), vector(3)
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
01 Feb 2012 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?

31 Jan 2012 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?

09 Nov 2011 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?

04 Nov 2011 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)

04 Nov 2011 Andreas  

Contact us