4.0

4.0 | 6 ratings Rate this file 155 downloads (last 30 days) File Size: 1.84 KB File ID: #9230

Gaussian Quadrature for Triangles

by Greg von Winckel

 

03 Dec 2005 (Updated 21 Dec 2005)

Code covered by BSD License  

Compute Gauss nodes and weights for a triangle

Download Now | Watch this File

File Information
Description

This script computes Gauss nodes and weights for numerically integrating a fuction over an arbitrary triangular domain. Note: This method uses the collapsed square rather than the general cubature case.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
05 Dec 2005 John D'Errico

A nice code, but with an error in the documentation -
the example usage fails. I'll assume that the author really
intended to write:

Q=Wx'*feval(f,X,Y)*Wy;

A quick test verifies that this did give the exact integral
on a simple linear function over a simple triangle.

I'll still rate it a 5, and hope the author chooses to fix the
documentation.

06 Dec 2005 Greg von Winckel

Thanks for catching that John. The comments have been corrected.

09 Aug 2006 Garrett Baird

I must be doing something wrong, because I can't get this to work for me. For example

[X,Y,Wx,Wy]=triquad(8,[0 0; 0 2; 2 0]);
f=@(x,y) x^2 + exp(y);
Q=Wx'*feval(f,X,Y)*Wy;

returns Q = 7.63, but the real answer is exp(3) - 5/3 which is around 5.7224. Increasing the number of quadrature points just makes Q higher.

12 Aug 2006 John D'Errico

Garrett defined his function improperly. The lack of a dot can be important in matlab.

f=@(x,y) x.^2 + exp(y);

30 Oct 2006 marki bugs

say vertices are (0,0), (1,0), (0,1)
I see this function & example works well, but besides f=(x,y) 1. I understand if I insert f=(x,y) 1, i should get the area of the triangle back. But I don't, am I not doing something wrong?

08 Nov 2006 Greg von Winckel

First, the area would not be 1, but rather 1/2. Second, you need to define a function like f=@(x,y) 1+0*(x.*y) to make sure it returns something with the correct dimension. Alternately, you could just sum the weights to get the area.

28 Mar 2007 zhenzhen Jin  
14 Aug 2007 YALA Hakim

I need this file for my code of FEM

04 Mar 2008 Im Serious

Does not integrate correctly

25 May 2008 meysam mousavi  
18 Aug 2008 DAR .

Seems good. Too much simple thought.

Please login to add a comment or rating.
Updates
07 Dec 2005

Missing transpose symbol in comments.

21 Dec 2005

Sign of weights depended on ordering of vertices through the Jacobian. This has been fixed.

Tag Activity for this File
Tag Applied By Date/Time
integration Greg von Winckel 22 Oct 2008 08:08:21
triangle Greg von Winckel 22 Oct 2008 08:08:21
triangular Greg von Winckel 22 Oct 2008 08:08:21
gauss Greg von Winckel 22 Oct 2008 08:08:21
quadrature Greg von Winckel 22 Oct 2008 08:08:21
cubature Greg von Winckel 22 Oct 2008 08:08:21
numerical Greg von Winckel 22 Oct 2008 08:08:21
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com