File Exchange

image thumbnail

2D trapezoidal rule

version 1.8 (2.26 KB) by

Calculates a double integral using trapezoidal rule.

11 Downloads

Updated

View License

This is a very simple program that makes use of Matlab's trapz (single integral). It has the benefit that it can be used to integrate over vectors x, y, and the function f(x,y), rather than on lower and upper limits. It can also be used with nonuniform spacing at the input vectors.

Example of nonuniform spacing:
x=[0,.1,.3,.45,.6,.8,.99,1]
y=[0,.05,.1,.2,.7,.57,.92,1]

Comments and Ratings (2)

Yes, that's a nice statement. But, I think it should be (according to the latest change)

result = trapz(y,trapz(x,mat,1),2);

Although I think keeping it as is is more illustrative. I will add it as a comment.

Thanks for the comment.
N.B. I am still not sure if it would perform faster/better than quad2d if one use it with empirical data.

Richard Crozier

Could be replaced with a single line:

result = trapz(x,trapz(y,mat,1),2);

Updates

1.8

Considering the suggestion
% Richard Crozier http://www.mathworks.com/matlabcentral/fileexchange/authors/34660

Thanks Richard :)

1.7

A simple correction to the example.

1.6

Modification so that the input matrix is MxN rather than NxN.

1.5

Adding one extra tag, keyword.

1.4

Adding one line to the code.

1.3

Description change.

1.2

Doing corrections to the comments.

1.1

Correcting the description.

MATLAB Release
MATLAB 7.1.0 (R14SP3)
Acknowledgements

Inspired: 3D Trapezoidal Rule

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video