Code covered by the BSD License  

Highlights from
2D trapezoidal rule

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

2D trapezoidal rule

by

 

05 Mar 2013 (Updated )

Calculates a double integral using trapezoidal rule.

| Watch this File

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)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
07 Mar 2013 Mohammed Sadeq Al-Rawi

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.

07 Mar 2013 Richard Crozier

Could be replaced with a single line:

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

Updates
05 Mar 2013

Correcting the description.

05 Mar 2013

Doing corrections to the comments.

06 Mar 2013

Description change.

06 Mar 2013

Adding one line to the code.

07 Mar 2013

Adding one extra tag, keyword.

07 Mar 2013

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

07 Mar 2013

A simple correction to the example.

07 Mar 2013

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

Thanks Richard :)

Contact us