# Problem with defining a bivariate piecewise function

I want to define the following function in Mathematica in order to evaluate its partial derivative later,

$$C(u,v)= (1+\theta) uv + \theta(u+v-1) F(u+v-1)$$

$$F(a)= 1\quad \text{if} \quad a \ge 0 \quad \text{and}\quad F(a)= 0\quad \text{if} \quad a< 0$$

First I tried the Max function,

theta1 = -0.0738;
c[u_, v_] := (1 + theta1)*u*v + theta1* Max[u + v - 1, 0];


But it seems, the function doesn't account for $$u+v-1 = 0$$. To fix this I tried a piecewise function,

theta1 = -0.0738;
c[u_, v_] :=
Piecewise[{{(1 + theta1)*u*v + theta1* (u + v - 1), (u + v - 1) >= 0},
{(1 + theta1)*u*v, (u + v - 1) < 0}}];


But the problem persists. To visualize it I plotted the function I wrote,

From the graph we can see it is not defined for some $$u$$ and $$v$$ (looks like $$u + v - 1=0$$). I'm wondering how to fix it.

Edit:

To be more specific, I want to plot $$\frac{\partial C(u,v)}{\partial u}\vert_{u= u_0}$$ for $$u_0\in \{0.25, 0.5, 0.75\}$$. Here is what happens for $$u=0.5$$,

• use Plot3D[c[u, v], {u, 0, 1}, {v, 0, 1}, Exclusions -> None] Commented Feb 19 at 6:55
• @RolandF My problem is not with the plot itself. I need to correctly define the function since I need to find its partial derivative. Commented Feb 19 at 6:59
• I don't see any problem Plot3D[[Piecewise] { {-0.0738 + 0.9262 v, u + v >= 1}, {0.9262 v, u + v < 1} }, {u, 0, 1}, {v, 0, 1}, Exclusions -> None] Commented Feb 19 at 7:08

Not reinventing the wheel,

theta1 = -0.0738;
c[u_?NumericQ, v_?NumericQ] := (1 + theta1)*u*v +
theta1*(u+v-1)*UnitStep[u + v - 1];
Plot3D[c[u, v], {u, 0, 1}, {v, 0, 1}]
Plot3D[Evaluate[D[c[u, v], u]], {u, 0, 1}, {v, 0, 1}, PlotPoints -> 50]


works well. The partial derivative is not continuous and defined on the line u+v-1==0.

\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global*"]

theta1 = -0.0738 // Rationalize;

c[u_, v_] := Piecewise[{{(1 + theta1)*u*v, u + v - 1 < 0}},
(1 + theta1)*u*v + theta1] // Simplify

D[c[u, v], {{u, v}}]

(* {(4631 v)/5000, (4631 u)/5000} *)