5
$\begingroup$

I want to be able to combine two piecewise functions. For example, suppose

Piecewise1 = f=3 for  1 <=x <=2  and
Piecewise2 = f=5 for 1.5<=x<=3, 

I want to insert Piecewise2 into Piecewise1 such that I get:

 f=3 for 1<x<1.5 and f=5 for 1.5<= x <3.

Notice that, for the overlap in [1.5,2], I prioritize the Piecewise I insert.

$\endgroup$
1
$\begingroup$
f1[x_] := Piecewise[{{3, 1 <= x <= 2}}];
f2[x_] := Piecewise[{{5, 1.5 <= x <= 3}}];
f[x_] := PiecewiseExpand[Insert[f2[x], f1[x][[1, 1]], {1, 2}]]
(* or f[x_] := PiecewiseExpand[Insert[f1[x], f2[x][[1, 1]], {1, 1}]] *)
f[x]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.