1

I have two functions f1 and f2. They have a square region in the $x-y$ plane as their domain. They might intersect, or they might not. Example:

f1["Domain"]
f2["Domain"]
(* {{-480., -180.}, {68., 268.}} *)
(* {{-729., -429.}, {68., 268.}} *)

I want to create a piecewise function that is defined by the following characteristics. For every point {x0, y0}:

  • if in exclusive f1 domain, return f1[$x_0,y_0$],
  • if in exclusive f2 domain, return f2[$x_0,y_0$],
  • if in intersection, return Max[f1[$x_0,y_0$],f2[$x_0,y_0$]],
  • if elsewhere, return 0.

How would I be able to do this?

corey979
  • 23,947
  • 7
  • 58
  • 101
triplebig
  • 287
  • 1
  • 8

1 Answers1

2
f1domain = {{-480., -180.}, {68., 268.}};
f2domain = {{-729., -429.}, {68., 268.}};

reg1 = ImplicitRegion[
 LessEqual @@ Riffle[First@f1domain, x] && LessEqual @@ Riffle[Last@f1domain, y],
       {x, y}];
reg2 = ImplicitRegion[
 LessEqual @@ Riffle[First@f2domain, x] && LessEqual @@ Riffle[Last@f2domain, y],
       {x, y}];

RegionPlot@{reg1, reg2}

enter image description here

v[x0_, y0_] := 
 Which[
  RegionMember[RegionDifference[reg1, reg2], {x0, y0}], 
   f1[x0, y0],
  RegionMember[RegionDifference[reg2, reg1], {x0, y0}], 
   f2[x0, y0],
  RegionMember[RegionIntersection[reg1, reg2], {x0, y0}], 
   Max@{f1[x0, y0], f2[x0, y0]}, 
  Not@RegionMember[RegionUnion[reg1, reg2], {x0, y0}],
   0
 ]

v[-600, 150]
v[-300, 150]
v[-450, 150]
v[-450, 1500]

f2[-600, 150]

f1[-300, 150]

Max[f1[-450, 150], f2[-450, 150]]

0

corey979
  • 23,947
  • 7
  • 58
  • 101
  • Thanks for the answer. As a further question, if you do not mind, I would like to know the following: How can I write a module that accepts f1 and f2 and returns v? Having a hard time with this one. I want to keep "stitching" more functions using this module. – triplebig Nov 23 '16 at 00:50
  • You'd have to create the regions and Which beforehand. With f1domain replaced with f1["Domain"], sth like func[x0_,y0_,f1_,f2_,...]:=Module[{reg1,reg2,...,v},v[x0_,y0_]:=...,reg1=...;reg2=...;v[x0,y0]] – corey979 Nov 23 '16 at 08:33