View License

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

» Watch video

Highlights from
2D trapezoidal rule

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

2D trapezoidal rule



05 Mar 2013 (Updated )

Calculates a double integral using trapezoidal rule.

| Watch this File

File Information

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:


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.

Comment only
07 Mar 2013 Richard Crozier

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

Doing corrections to the comments.

06 Mar 2013 1.3

Description change.

06 Mar 2013 1.4

Adding one line to the code.

07 Mar 2013 1.5

Adding one extra tag, keyword.

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

Thanks Richard :)

Contact us