# Compute the area of the union of the intersections of two conditions

I have four conditions over the two-dimensional domain $$x,y\in[a,b]$$. I want to use NIntegrate to compute the area of the union of the intersection of the two conditions con1 and con2 with the intersection of the two conditions con3 and con4, i.e. the region $$(con1 \cap con2)\cup(con3 \cap con4)$$. Does the following code give me the correct answer?

NIntegrate[
Boole[{con1 && con2}, {con3 && con4}],
{x, a, b}, {y, a, b}
]

• I'm confused.... Why can't you tell if it gives you the correct answer? May 10 at 22:26
• @DavidG.Stork Corrected :) May 11 at 9:56
• I still am confused. Why don't you simply try your code on an example and see if it gives the correct answer?? Be explicit about the conditions... that's all. I don't see how we can help you if you don't try your code. May 11 at 10:40
• @DavidG.Stork Since I do not know the area of my desired condition analytically, they can be computed only numerically, and NIntegrate was the only way I knew! If it is so clear, why cannot you answer if this code is correct in general (for any conditions and not only for an example) or not? My question is for a general situation not only for a particular example! May 11 at 10:54
• It is NOT so clear, and I never said that. Your accepted "answer" from CraigCarter shows a single example (the kind you could have and should have done on your own), but doesn't answer the full general problem. Are you now positive that CraigCarter's solution will work for every case you have in mind? May 11 at 15:48

You could compare it in this fashion:

ir1 = ImplicitRegion[
x + y < 1 && x - y <  1, {{x, -2, 2}, {y, -2, 2}}]

ir2 = ImplicitRegion[
x + y > 0 && x - y >  0, {{x, -2, 2}, {y, -2, 2}}]

RegionPlot[RegionUnion[ir1, ir2]]

Integrate[1, {x, y} \[Element] RegionUnion[ir1, ir2] ]


or

NIntegrate[1, {x, y} \[Element] RegionUnion[ir1, ir2] ]

• Thanks! Now, I see that my ode is fundamentally wrong; this part Boole[{con1 && con2}, {con3 && con4}] becomes red when I try to run it. So, my desired area can be computed in the way you mentioned. May I ask you to explain what $1$ stands in your Integrate or NIntegrate code? Sorry if it is a primary question; I am a beginner in Mathematica. May 11 at 11:01
• And if my conditions are very complicated, and if it is needed to increase the precision of the result, where I should add PlotPoints,  Precision , or MaxRecursion in your code? May 11 at 11:09
• {x, y} \[Element] RegionUnion[ir1, ir2] is analogous to the region you want. It is equivalent to "dA" for a two dimensional integral. So, integrating 1 over dA gives you the area you want. I left the NIntegrate as an option. If your region is a meshed region, you will need to do a numerical approximation. HTH. May 11 at 14:38