Find and plot the best parabola separating the points \((2,3)\text{,}\) \((4,6)\text{,}\) and \((7,4)\) (the “top” group) from \((3,4)\) and \((5,5)\) (the “bottom” group).
Solution.
We maximize \(w\) subject to constraints \(y_k\ge ax_k^2 + bx_k + c + w\) in the first group and \(y_k\le ax_k^2 + bx_k + c - w\) in the second. Rewrite the constraints as
\begin{equation*}
ax_k^2 + bx_k + c + w \le y_k
\end{equation*}
in the first group and
\begin{equation*}
-ax_k^2 - bx_k - c + w \le -y_k
\end{equation*}
in the second. Also, \(w\ge 0\) is required by the geometric meaning of \(w\) as the “width” of separation. Given the vectors
xt, yt describing the first group and xb, yb for the second, we can form a system of linear inequalities \(A\mathbf x\le \mathbf b\) as belowxt = [2; 4; 7]; yt = [3; 6; 4]; xb = [3; 5]; yb = [4; 5]; A = [xt.^2 xt xt.^0 xt.^0; -xb.^2 -xb -xb.^0 xb.^0; 0 0 0 -1]; b = [yt; -yb; 0]; opt = linprog([0; 0; 0; -1], A, b); t = linspace(min([xt; xb]), max([xt; xb]), 1000); y = opt(1)*t.^2 + opt(2)*t + opt(3); plot(xt, yt, 'b*', xb, yb, 'r*', t, y, 'k')
Instead of including \(-w \le 0\) as one of the inequalities in the system \(A\mathbf x\le b\text{,}\) we can impose this constraint separately as a lower bound in
linprog.
A = [xt.^2 xt xt.^0 xt.^0; -xb.^2 -xb -xb.^0 xb.^0]; b = [yt; -yb]; opt = linprog([0; 0; 0; -1], A, b, [], [], [-Inf; -Inf; -Inf; 0]);
The result is the same. With either version of the code, if the data points are changed so that there is no parabola that separates them completely, we get the message “No feasible solution found. Linprog stopped because no point satisfies the constraints.”
