Message Boards Message Boards


Integrate of 2D piecewise function with constants?

Posted 5 months ago
1 Reply
0 Total Likes

My question is about letting Mathematica automatically find the constants for the different pieces of a piecewise defined function. This works fine in case of 1D piecewise function, but not for a 2D function. At least I do not know what I'm doing wrong. Here is the integration of the 1D piecewise function that does work:

tent[x_] = Piecewise[{{x + 1, -1 <= x < 0}, {-x + 1, 0 <= x <= 1}}] 
itent[x_] = Integrate[tent[x], x] 

itent evaluates nicely to:

{0, x <= -1}, 
{1/2 + x + x^2/2, -1 < x <= 0}, 
{1/2 + x - x^2/2, 0 < x <= 1}}, 

However when I apply (single) vertical integration on a 2D function the constants are not found anymore:

tent2D[x_, y_] = tent[x]*tent[y]
HyNoConst[x_, y_] = Integrate[tent2D[x, y], y]

Have a look to the attache notebook file (Mathematica version 9). Here output of above HyNoConst is printed and plotted. It is clear that the pieces in the piecewise function are integrated as if they were separately integrated; without taking account for the integrated value of adjoining piecewise parts. Find at the bottom of the attached notebook the HyExpected, where I manually added the vertical integration constants, which I expect Mathematica to find automatically. Also a plot of HyExpected is shown which makes it clear why this is the expected outcome.


You expect Mathematica to find the continuation because Piecewise says in Examples -> Scope

Integration constants are chosen to make the result continuous:

which is correct in one dimension. In 2 or more dimensions two problems arise (as you found)

  • the integral is given only on the actual support of the piecewise function
  • it's generally not the job of indefinite Integrate[] to fix integration constants

But one reaches the intended result without labour:

In[1]:= tent[x_] := Piecewise[{{x + 1, -1 <= x < 0}, {1 - x, 0 <= x <= 1}}]
In[2]:= tent2[x_, y_] := PiecewiseExpand[tent[x] tent[y]] 
In[3]:= Clear [stamm]
        stamm[x_, y_] := Evaluate[Integrate[tent2[x, y1], y1] /. y1 -> y]
In[5]:= Clear[stammC]
        stammC[x_, y_] := stamm[x, y] - If[y < -1, 0, If[y < 1, stamm[x, -1], stamm[x, -1] - stamm[x, 1]]]

In[8]:= Plot3D[PiecewiseExpand[stammC[x, y]], {x, -1.6, 1.6}, {y, -1.6, 2.6}, AxesLabel -> {"X", "Y", "Z"}]

which is your Plot3D[HyExpected[x, y], {x, -1.6, 1.6}, {y, -1.6, 2.6}, PlotRange -> Full]:

enter image description here

If one muses about it one will see that's in general not easy to find the intended integration constants (Piecewise[] can go in irregular shapes (i.e. not axis-parelle) etc. etc.), but the problem owner can do.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract