# Draw function with different colors associated to a parameter

I want to generate a plot similar to this one, which allows for different colors when given different parameters : (This is the Moreau-Yosida regularization of the absolute value)

the Moreau-Yosida regularization is given by :

$$f_{\lambda}(x):= \inf_{u\in \mathbb{R}}\left\lbrace f(u)+ \dfrac{1}{2 \lambda} |x-u|^2 \right\rbrace$$

I want to show these functions in the same plot:

• Absolute value function
• the Moreau-Yosida regularization of the $0-norme$ with different values of $\lambda$ to get this kind of color progression (aesthetically, I think a luminosity progression with a single color would look better than the rainbow colors) ( $|x|_0 = 0$ if $x=0$ and $|x|_0 = 1$ otherwise)
• the Moreau-Yosida regularization of the Absolute value function with different values of $\lambda$ and the same criteria as above.

The following code is my first attempt to set up the visualization I want to get:

Manipulate[
Plot[{Abs[x],
1/(2 \[Lambda]) * (Abs[x]^2 - Max[Abs[x]^2 - 2 \[Lambda], 0]),
1/(2 b) * (Abs[x]^2 - Max[Abs[x] - b, 0]^2)}, {x, -2,
2}] , {\[Lambda], 1/1000, 1}, {b, 1/1000, 1}]

• Thank you @dionys for editing, I hope my English get better someday. – Aymane Fihadi Oct 18 '14 at 20:10

EDIT

Thank you for comment from ybeltukov: Exclusions->None:

fun[b_, x_] := 1/(2 b)*(Abs[x]^2 - Max[Abs[x] - b, 0]^2)
Legended[ParametricPlot[{u, fun[a, u]}, {u, -2, 2}, {a, 0, 1},
ColorFunction -> {ColorData["Rainbow"][#4] &}, Exclusions -> None,
ImageSize -> 500], BarLegend["Rainbow"]]


• Exclusions -> None removes artifacts. It is also 2.5 times faster. – ybeltukov Oct 18 '14 at 13:01
• @ybeltukov thank you I have edited – ubpdqn Oct 18 '14 at 13:08
• Thank you very much @ubpdqn. Can you pleas explain the part {ColorData["Rainbow"][#4] &} of the code? ( what is the function of the argument #4 and the & in the end) ;) And how can we do the Color gradient with one color?, say from gray 10 % to gray 100% (black) – Aymane Fihadi Oct 18 '14 at 14:03
• @AymaneFihadi #4 just the slot for b in parameter space (x,b). I suggest looking at documentation of ColorFunction and ColorData and playing. – ubpdqn Oct 18 '14 at 21:46