Code covered by the BSD License

### Highlights from 2D trapezoidal rule

Be the first to rate this file! 6 Downloads (last 30 days) File Size: 2.26 KB File ID: #40631 Version: 1.8

# 2D trapezoidal rule

### Mohammed Sadeq Al-Rawi (view profile)

05 Mar 2013 (Updated )

Calculates a double integral using trapezoidal rule.

File Information
Description

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]

Acknowledgements

This file inspired 3 D Trapezoidal Rule.

Required Products MATLAB
MATLAB release MATLAB 7.1.0 (R14SP3)
07 Mar 2013 Mohammed Sadeq Al-Rawi

### Mohammed Sadeq Al-Rawi (view profile)

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.

Comment only
07 Mar 2013 Richard Crozier

### Richard Crozier (view profile)

Could be replaced with a single line:

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

Comment only
05 Mar 2013 1.1

Correcting the description.

05 Mar 2013 1.2

06 Mar 2013 1.3

Description change.

06 Mar 2013 1.4

Adding one line to the code.

07 Mar 2013 1.5

07 Mar 2013 1.6

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

07 Mar 2013 1.7

A simple correction to the example.

07 Mar 2013 1.8

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

Thanks Richard :)