Fitting piecewise linear function


I have some data which needs to fit the convex piecewise linear function

I want to determine the values of a and b from the fit. Is there a function in cvx that can do the fitting or do I have to write the iterative algorithm myself? Also, are there examples for convex piecewise linear fitting in the software package that I could look at?


You could take a look at this code:

But no, CVX cannot do this for you.

Thanks for the help.

Hi, Michael C. Grant.
Now I have some three-dimensional data points such as (x,y,z),Could you please tell me how to fit these data points to a convex function such as z=f(x,y)?Or could please give a example?
Thank you very much.

In addition,The result that is obtained by the way of ( seemly can not use in cvx when the variable is a vector.