File Exchange

version 1.1 (5.56 KB) by

4.66667
3 Ratings

Updated

In almost every standard book on numerics quadrature algorithms like the adaptive Simpson or the adaptive Lobatto algorithm are presented in a recursive way. The benefit of the recursive programming is the compact and clear representation. However, recursive quadrature algorithms might be transformed into iterative quadrature algorithms without major modifications in the structure of the algorithm.

Elias

Elias (view profile)

does it work on vectors or matrixes ??

Elias

Elias (view profile)

x=[1,1,1,1,1,1,1,1,1,1,1,1]
i get an error
how can i use the adaptivelobatto in this case

Martin

Martin (view profile)

Hi Matthias,
I have tried to use your codes to improve the speed of my functions.
Though if I use the example from your codes:
Q = adaptiveSimpson(@(x) [-cos(50*x); sin(x)], 0, pi, 'tol', 1e-6)
I get the following error:
Undefined function 'adaptiveSimpson' for input arguments of type 'function_handle'.

How come?

Stephan Koehler

Stephan Koehler (view profile)

this works much faster than MATLAB's quadv, because quadv does not vectorize (i.e. it evaluates the function using only single values).

Matthias Chung

Matthias Chung (view profile)

It is very easy to pass arguments to the "anonymous" function. As I recall correctly, since Matlab 6 the "@" function is exactly doing what you want. Here is an example

y = c1; f1 = @(x) f(x,y);

x = c2; f2 = @(y) f(x,y);

This makes your code more clear than passing all the arguments to the "anonymous" function.

Best,

Matthias

pedro pablo perez velasco

pedro pablo perez velasco (view profile)

Very nice. Congratulations.

It should be very helpful to permit passing arguments to the "anonymous" function (the one that defines the function to be integrated) very much like quad, quadl and the like. For example, to perform integration in several variables.

Regards,
P.P.

I updated the files. The requested H1-line have been added. An example in the comment-lines show how to handle algorithm parameters.

It is easy to change the parameters, please use

example:

Q = adaptiveLobatto(@(x) [-cos(50*x); sin(x)], 0, pi, 'tol', 1e-6)

I will update some comments in the code soon.
Thanks
Matthias

Matt Fig

For the adaptiveLobatto function, extra arguments aren't recognized. For example:

f = @(x) 25*exp(-25*t);
returns the same result as

If, however, I go in and change the tolerance manually, on line 53 (default values), this has the intended outcome. There is something funny about the way varargin is handled. I didn't check the other function.

John D'Errico

These seem to be well written codes, often clearly out-performing the tools provided by MATLAB (quad, quadv, quadl.) Well done, and my compliments to the authors for providing these tools.

I'll make only one plea - to add H1 lines to your codes. While the authors will remember the names of these functions next year, or next month, when I want to find them, I won't remember the names. I'll try to use the lookfor utility, that will search through the first line of every function for a logical keyword that I'll provide. But, since the authors have not provided an H1 line here, lookfor will fail. So, I'll never be able to recall the names of these functions when I need them.

Enable the facilities in MATLAB that help you and your users to use it most efficiently. It takes only a minute more to write that H1 line (the very first line of comment in the help block.)

I'll choose not to downgrade these tools for that lack, hoping instead that the authors will repair the flaw.