Re: How to integrate a function over a polygon

• To: mathgroup at smc.vnet.net
• Subject: [mg123291] Re: How to integrate a function over a polygon
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Wed, 30 Nov 2011 03:22:38 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <201111291203.HAA05398@smc.vnet.net>

```The result of the division of polynomials of more than one variable
depends on the order of the variables. When you specify the order of the
variables PolynomialReduce uses your order. When you don't specify it or
specify it, it uses the canonical order. For example:

PolynomialReduce[x^2 y + x y^2 + y^2, y + x - 1, {x, y}]

{{y + x y}, y}

PolynomialReduce[x^2 y + x y^2 + y^2, y + x - 1, {y, x}]

{{1 + y + x y}, 1 - x}

PolynomialReduce[x^2 y + x y^2 + y^2, y + x - 1]

{{y + x y}, y}

PolynomialReduce[x^2 y + x y^2 + y^2, y + x - 1, x]

{{y + x y}, y}

PolynomialReduce[x^2 y + x y^2 + y^2, y + x - 1, {x, x, x}]

{{y + x y}, y}

etc.

Andrzej Kozlowski

On 29 Nov 2011, at 13:03, Mikael wrote:

> Thanks Andrzej but that is exactly the part in PolynomialReduce which
I do not understand. As I mentioned you get also exactly the same answer
if you change the last argument to {z, x} or {z}. So I would appreciate
if someone could explain the meaning of the last argument in
PolynomialReduce.
>
> In a related question I wonder how one can plot g[x,y] over only the
2-dimensional unit simplex.
>
> Many thanks to all in advance.
>
> /Mikael
>
>> Actually, that was a mistake ;-) It should have been
>>
>> f[x_, y_, z_] := x^2 + y^2 + z^2
>>
>> Expand[
>> Last[PolynomialReduce[f[x, y, z], {x + y + z - 1},
>> , {z, x, y}]]]
>>
>> 1 - 2 x + 2 x^2 - 2 y + 2 x y + 2 y^2
>>
>> But luckily it made not difference ;-)
>>
>>
>> In this particular case PolynomialReduce was an
>> overkill. You could
>> equally well use a simple replacement:
>>
>> g[x_,y]:=x^2 + y^2 + z^2 /. z -> (1 - x - y) //
>> Expand
>>
>> 1 - 2 x + 2 x^2 - 2 y + 2 x y + 2 y^2
>>
>>
>> PolynomialReduce could be useful if you wanted to
>> integrate over a more
>> complicated non-linear regions, when a simple
>> syntactical substitution
>> might not be possible.
>>
>> Andrzej Kozlowski
>>
>>
>> On 27 Nov 2011, at 10:14, Mikael wrote:
>>
>>> Many thanks indeed for your elegant solution,
>> Andrzej. May I ask a
>> related question regarding the last argument in
>>>
>>> Expand[Last[PolynomialReduce[f[x, y, z], {x + y + z
>> - 1}, {z, x,
>> z}]]].
>>>
>>> I wonder what is the role of {z, x, z} there. I get
>> the same answer if
>> I change it to {z, x} or {z} and I could not figure
>> it out from the help
>> page for PolynomialReduce either.
>>>
>>> /Mikael
>>>
>>>
>>>
>>>
>>>> Well, perhaps you mean this. Let the function be:
>>>>
>>>> f[x_, y_, z_] := x^2 + y^2 + z^2
>>>>
>>>> We want to integrate it over the simplex:
>> x+y+z==1,
>>>> 0<=x<=1,0<=y<=1,0<=y<=1
>>>>
>>>> On the simplex the function can be expressed in
>> terms
>>>> of only x and y as follows:
>>>>
>>>> g[x_, y_] =
>>>> Expand[Last[PolynomialReduce[f[x, y, z], {x + y +
>> z
>>>> z - 1}, {z, x, z}]]]
>>>>
>>>> 2*x^2 + 2*x*y - 2*x + 2*y^2 - 2*y + 1
>>>>
>>>> In terms of x and y the simplex can be described
>> as:
>>>>
>>>> cond[x_, y_] := x + y <= 1 && 0 <= x <= 1 && 0 <=
>> y
>>>> <= 1
>>>>
>>>> So now we simply compute:
>>>>
>>>> Integrate[Boole[cond[x, y]]*g[x, y], {x, 0, 1},
>> {y,
>>>> 0, 1}]
>>>>
>>>> 1/4
>>>>
>>>>
>>>> Andrzej Kozlowski
>>>>
>>>>
>>>> On 25 Nov 2011, at 10:57, Mikael wrote:
>>>>
>>>>> Well, as I wrote in my OP, it is a 2-diemnsional
>>>> unit simplex so you can always re-parametrize the
>>>> function to have 2 arguments.
>>>>>
>>>>> In any case, your answer is not useful unless you
>>>> had also answered the original question apart from
>>>>>
>>>>>> First of all, f would need three arguments.
>>>>>>
>>>>>> Bobby
>>>>>>
>>>>>> On Wed, 23 Nov 2011 06:07:00 -0600, Mikael
>>>>>> <mikaen.anderson.1969 at gmail.com> wrote:
>>>>>>
>>>>>>> The subject line asks the general question but
>> to
>>>>>> be more specific
>>>>>>> suppose I have a 2-dimentional unit simplex
>>>> defined
>>>>>> as
>>>>>>>
>>>>>>> Polygon[{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}].
>>>>>>>
>>>>>>> I winder how I can integrate a function f(x,y)
>>>> over
>>>>>> this simplex. Thanks.
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> DrMajorBob at yahoo.com
>>>>>>
>>>>>
>>>>
>>>>
>>>
>>
>>
>

```

• Prev by Date: Re: Ragged region boundary
• Next by Date: Re: How to sort elements from a two-dimensional list
• Previous by thread: Re: How to integrate a function over a polygon
• Next by thread: Sorting strings