# Optimization problem over two variables

Given the function fun1[a, b, x] , I want minimize this function over $$a$$ and $$b$$ such that $$0\le a \le 2\pi$$ and $$0\le b\le 2\pi$$, and plot the resulting function w.r.t. variable $$x$$. The following attempt doesn't seem to work:

  fun1[a_, b_, x_] = -2 + Sqrt[1 + x^2 - 2 x Cos[a]] + Sqrt[
2 - 2 Cos[b]] + Sqrt[1 + x^2 + 2 x Cos[a + b]];
fun2[x_] := fun1[a, b, x] /. Last[NMinimize[fun1[a, b, x], {a, b}]]

tab = Table[fun2[x], {x, 0, 1, 0.001}];
ListPlot[tab]


Further, I need to find the values of $$a$$ and $$b$$ for which fun1[a, b, x]is less or equal to zero.

You should pattern test the arguments for NumericQ. The replacement is unnecessary - the first element of the result of NMinimize is this minimum of the function. In your plot you probably want to plot {x,fun2[x]} if you want to pick up the x-coordinates too. I used ParallelTable to generate the results in parallel. And finally, I noticed also that NMinimize has trouble converging, so I added MaxIterations -> 200:
fun1[a_?NumericQ, b_?NumericQ, x_?NumericQ] :=