From: Vivek Saxena on 20 Mar 2010 00:50 Hi, I'm wondering if it is possible to perform a double integral in MATLAB like \int \int f(x,y) dx dy where the domain of integration is a triangle, whose vertex coordinates are known? A full question is posted here: http://www.physicsforums.com/showthread.php?t=388101. Thanks in advance!
From: Steven Lord on 20 Mar 2010 01:01 "Vivek Saxena" <maverick280857(a)yahoo.com> wrote in message news:ho1k5u$hsc$1(a)fred.mathworks.com... > Hi, > > I'm wondering if it is possible to perform a double integral in MATLAB > like > > \int \int f(x,y) dx dy > > where the domain of integration is a triangle, whose vertex coordinates > are known? > > A full question is posted here: > http://www.physicsforums.com/showthread.php?t=388101. Look at QUAD2D. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Vivek Saxena on 20 Mar 2010 01:35 "Steven Lord" <slord(a)mathworks.com> wrote in message <ho1kqh$qvl$1(a)fred.mathworks.com>... > > "Vivek Saxena" <maverick280857(a)yahoo.com> wrote in message > news:ho1k5u$hsc$1(a)fred.mathworks.com... > > Hi, > > > > I'm wondering if it is possible to perform a double integral in MATLAB > > like > > > > \int \int f(x,y) dx dy > > > > where the domain of integration is a triangle, whose vertex coordinates > > are known? > > > > A full question is posted here: > > http://www.physicsforums.com/showthread.php?t=388101. > > Look at QUAD2D. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > Thanks Steve. The approach I thought to define c(x) and d(x) is based on the equations of the sides of the triangle (defining the boundaries of the area element). But there are several possibilities depending on how the triangle is oriented with respect to the axes: an edge could have a zero slope, a nonzero finite slope or an infinite slope, and the different permutations of the ordering of the vertices will probably also play a role in defining c(x) and d(x) differently, for different triangles. Is there a neater way to employ QUAD2D to find the integral of f(x,y) over a triangular region with arbitrary vertex locations (x1, y1), (x2, y2) and (x3, y3)?
From: Roger Stafford on 20 Mar 2010 02:02 "Vivek Saxena" <maverick280857(a)yahoo.com> wrote in message <ho1k5u$hsc$1(a)fred.mathworks.com>... > I'm wondering if it is possible to perform a double integral in MATLAB like > \int \int f(x,y) dx dy > where the domain of integration is a triangle, whose vertex coordinates are known? If it happens you don't have quad2d, you can use the older dblquad which integrates over rectangular regions by making a change of variable from x,y to u,v defined by: x = (1-u)*x2 + u*((1-v)*x2 + v*x3) y = (1-u)*y2 + u*((1-v)*y2 + v*y3) where (x1,y1), (x2,y2), and (x3,y3) are the triangular region's three vertices. Of course you must change dx dy in the double integral to du dv with the proper Jacobian factor. What was the triangular region in x,y space then becomes a unit square in u,v space - the variables u and v each range from 0 to 1. Of course it is more convenient to use quad2d if you have it. Roger Stafford
From: Vivek Saxena on 20 Mar 2010 02:29
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <ho1ocu$ldr$1(a)fred.mathworks.com>... > "Vivek Saxena" <maverick280857(a)yahoo.com> wrote in message <ho1k5u$hsc$1(a)fred.mathworks.com>... > > I'm wondering if it is possible to perform a double integral in MATLAB like > > \int \int f(x,y) dx dy > > where the domain of integration is a triangle, whose vertex coordinates are known? > > If it happens you don't have quad2d, you can use the older dblquad which integrates over rectangular regions by making a change of variable from x,y to u,v defined by: > > x = (1-u)*x2 + u*((1-v)*x2 + v*x3) > y = (1-u)*y2 + u*((1-v)*y2 + v*y3) > > where (x1,y1), (x2,y2), and (x3,y3) are the triangular region's three vertices. Of course you must change dx dy in the double integral to du dv with the proper Jacobian factor. What was the triangular region in x,y space then becomes a unit square in u,v space - the variables u and v each range from 0 to 1. > > Of course it is more convenient to use quad2d if you have it. > > Roger Stafford Thanks Roger. But didn't you mean x = (1-u)*x1 + u*[(1-v)*x2 + v*x3] y = (1-u)*y1 + u*[(1-v)*y2 + v*y3] because the coordinate map you gave doesn't involve x1 and y1. But even so, this becomes a triangle in (u, v) space because u = 0, v = 0 => x = x1, y = y1 u = 0, v = 1 => x = x1, y = y1 u = 1, v = 0 => x = x2, y = y2 u = 1, v = 1 => x = x3, y = y3 Only the last 3 coordinates are meaningful essentially, because if u = 0, the way this map is constructed, the value of v becomes meaningless. Perhaps you meant something else? |