# Using MaxValue to define a function, plotting is slow

I'm trying to compute c-functions (from the theory of optimal transport), and so I must compute supremums' for some function $$f$$ and cost $$c$$ $$g(y)=\sup_{x\in \mathbb{R}} c(x,y)-f(x)$$

My code works but the plotting is super slow.

c[x_,y_]:=-Log[Abs [x-y]+1]
f[x_]:= Piecewise[{{E^(-x^2), x>0},{E^((-x^2)/5),x<=0}}]
h[x_,y_]:=c[x,y]-f[x]
g[y_]:=MaxValue[h[x,y],x]
Plot[f[x],{x,-1,1},PlotLabel->"f"]
Plot[g[y],{y,-1,1},PlotLabel->"f^c"]


How can I make the plotting faster? I'm new to this :)

• Plot3D[h[x, y], {x, -1, 1}, {y, -1, 1}] and ContourPlot[h[x, y], {x, -1, 1}, {y, -1, 1}, PlotLegends -> Automatic]` may help. – OkkesDulgerci Apr 15 at 13:07