# Plot3D with restrictions through equalities and inequalities

It all stems from this optimization problem:

NMaximize[{-((7/40 + c^2/7)/(1/10 + 2 c/7)) + ((1 - d/(14 (1/10 + 2 c/7))) Sqrt[1 + d^2])/d,
d == ((1/10 + 2 c/7) (1 - d/(14 (1/10 + 2 c/7))))/(7/40 + 2/7 c (c/2 + d^2/(8 c))) &&
7/2 >= 2 d >= 0 && d <= c <= 7/2 - d}, {c, d}]


{0.40194, {c -> 1.04187, d -> 0.920991}}

Since I would like to visualize this graphically, I thought I'd write:

Plot3D[ConditionalExpression[
-((7/40 + c^2/7)/(1/10 + 2 c/7)) + ((1 - d/(14 (1/10 + 2 c/7))) Sqrt[1 + d^2])/d,
d == ((1/10 + 2 c/7) (1 - d/(14 (1/10 + 2 c/7))))/(7/40 + 2/7 c (c/2 + d^2/(8 c))) &&
7/2 >= 2 d >= 0 && d <= c <= 7/2 - d], {c, 0, 5}, {d, 0, 5}]


It's evident that something has gone wrong but I don't understand what. Ideas? Thank you!

Since the restrict conditon

((1/10 + 2 c/7) (1 - d/(14 (1/10 + 2 c/7))))/(7/40 +
2/7 c (c/2 + d^2/(8 c))) - d==0


is the curve on Plot3D, so we need to use Mesh to draw it,that is we define mesh[c,d] and set Mesh->{{0}} to view the curve mesh[c,d]==0 on surface.

Clear[sol, reg, f, mesh]; sol =
NMaximize[{-((7/40 + c^2/7)/(1/10 + 2 c/7)) + ((1 -
d/(14 (1/10 + 2 c/7))) Sqrt[1 + d^2])/d,
d == ((1/10 + 2 c/7) (1 - d/(14 (1/10 + 2 c/7))))/(7/40 +
2/7 c (c/2 + d^2/(8 c))) && 7/2 >= 2 d >= 0 &&
d <= c <= 7/2 - d}, {c, d}];
reg = ImplicitRegion[7/2 >= 2 d >= 0 && d <= c <= 7/2 - d, {c, d}];
f[c_, d_] = -((7/40 + c^2/7)/(1/10 + 2 c/7)) + ((1 -
d/(14 (1/10 + 2 c/7))) Sqrt[1 + d^2])/d;
mesh[c_, d_] = ((1/10 + 2 c/7) (1 - d/(14 (1/10 + 2 c/7))))/(7/40 +
2/7 c (c/2 + d^2/(8 c))) - d;
Show[
Plot3D[f[c, d], {c, d} ∈ reg,
MeshFunctions -> {mesh[#1, #2] &}, Mesh -> {{0}},
MeshStyle -> Directive[AbsoluteThickness[1], Green],
PlotStyle -> Opacity[.1], PlotPoints -> 40, MaxRecursion -> 2],
Graphics3D[{AbsolutePointSize[5], Red,
Point[{c, d, f[c, d]}] /. sol[[2]]}],
ViewPoint -> {2.6, -0.55, 2.0}]