Message Boards Message Boards

0
|
4244 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Do logically defined integration limits work?

Posted 8 years ago

This is possibly a better question for customer care but I want first to know whether the bug was fixed in higher versions of Mathematica. The following code was tested in Mathematica 10.0.2 and 9.0.1. Maybe someone can test it in a higher (or just different) version. As one can see, it does not work. And it does not give an error message but an erroneous result.

If in the integration limits gives erroneous results

In[1]:= f[x_, y_] = a + b x + c y;

Definition of integration limits; it checks out

In[2]:= g[x_] = If[x < r/2 \[Or] x > s - r/2, r/2, (s - r)/2];
Simplify[g[(s - r)/2], Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]
Simplify[g[s/2], Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]
Simplify[g[(s + r)/2], Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]

Out[3]= r/2

Out[4]= 1/2 (-r + s)

Out[5]= r/2

In[6]:= h[x_] = If[x < r/2 \[Or] x > s - r/2, s - r/2, (s + r)/2];
Simplify[h[(s - r)/2], Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]
Simplify[h[s/2], Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]
Simplify[h[(s + r)/2], Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]

Out[7]= -(r/2) + s

Out[8]= (r + s)/2

Out[9]= -(r/2) + s

Symbolic definite integral; it gives the wrong result; assumptions do not make any difference

In[10]:= Integrate[f[x, y], {x, (s - r)/2, (s + r)/2}, {y, g[x], h[x]}, 
 Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]

Out[10]= -(1/2) r (r - s) (2 a + (b + c) s)

In[11]:= Integrate[f[x, y], {x, (s - r)/2, (s + r)/2}, {y, g[x], h[x]}]

Out[11]= -(1/2) r (r - s) (2 a + (b + c) s)

Separate symbolic definite integrals; the correct result

In[12]:= I1 = Integrate[f[x, y], {x, (s - r)/2, r/2}, {y, r/2, s - r/2}];
I2 = Integrate[f[x, y], {x, r/2, s - r/2}, {y, (s - r)/2, (s + r)/2}];
I3 = Integrate[f[x, y], {x, s - r/2, (s + r)/2}, {y, r/2, s - r/2}];
Simplify[I1 + I2 + I3]

Out[15]= -(1/2) (2 a + (b + c) s) (3 r^2 - 4 r s + s^2)
POSTED BY: Petre Logofatu

If is fundamentally a procedural programming construct. It's evaluation semantics do not lend themselves to playing nicely with Integrate or other math functions. I would recommend using Piecewise as it is designed exactly for usage in math functions.

f[x_, y_] := a + b x + c y
g2[x_] := Piecewise[{{r/2, x < r/2 \[Or] x > s - r/2}}, (s - r)/2]
h2[x_] := Piecewise[{{s - r/2, x < r/2 \[Or] x > s - r/2}}, (s + r)/2]

Integrate[ f[x, y], {x, (s - r)/2, (s + r)/2}, {y, g2[x], h2[x]},  Assumptions -> r > 0 \[And] r > s/2 \[And] r < s]

(* Out[5]= 1/2 (-6 a r^2 + 8 a r s - 3 b r^2 s - 3 c r^2 s - 2 a s^2 + 
   4 b r s^2 + 4 c r s^2 - b s^3 - c s^3) *)
POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract