∇ProvenDecisions
Ctrl K

Minimax (Chebyshev) line fit: a linear programming example, solved and checked

The minimax (Chebyshev) line fit is a classic linear programming problem. Here it is solved by a real solver (HIGHS) and checked: every constraint, the dual, and the optimality certificate. Change the numbers below and solve your own.

Answer. The smallest objective value is 0.5, at d = 0.5, a = 0.5, b = 1. All 11 constraints are satisfied exactly. Exactly proven optimal.

Solve your own version free, no account needed

The problem

Fit y = a + b t to the points (0, 1), (1, 2), (2, 2), (3, 4), (4, 5) minimizing the largest absolute residual.

How the model was built

The objective as written from the problem, before the numbers are multiplied out:

The model

Each line has a plain-language note on the right.

make this as small as possible
limit 1: left side must reach at least the right side
limit 2: left side must reach at least the right side
limit 3: left side must reach at least the right side
limit 4: left side must reach at least the right side
limit 5: left side must reach at least the right side
limit 6: left side must reach at least the right side
limit 7: left side must reach at least the right side
limit 8: left side must reach at least the right side
limit 9: left side must reach at least the right side
limit 10: left side must reach at least the right side
largest absolute residual (y units) cannot be negative

In matrix form

With its numbers:

What is being decided

There are 3 decision variables.

VariableTypeMeaning
dreal numberlargest absolute residual (y units)
areal numberintercept of fitted line (y units)
breal numberslope of fitted line (y per unit t), free sign

Goal and limits

Minimize the objective subject to 11 constraints, of which 1 are simple bounds on a single variable.

Problem type

LP, complexity level 2: a linear program. Solved with HIGHS at the Medium solver tier.

The answer at a glance

The optimal value of each decision, as the solver returned it.

d0.5a0.5b1

Which constraints hold the answer in place

Binding (no slack left): (1) d >= 1 - a; (3) d >= -a - b + 2; (6) d >= a + 2*b - 2; (7) d >= -a - 3*b + 4; (9) d >= -a - 4*b + 5. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1d >= 1 - a0.50.50yes
2d >= a - 10.5-0.51
3d >= -a - b + 20.50.50yes
4d >= a + b - 20.5-0.51
5d >= -a - 2*b + 20.5-0.51
6d >= a + 2*b - 20.50.50yes
7d >= -a - 3*b + 40.50.50yes
8d >= a + 3*b - 40.5-0.51
9d >= -a - 4*b + 50.50.50yes
10d >= a + 4*b - 50.5-0.51
11d >= 00.500.5

Why this is optimal

A proof you can check by hand. Multiply each constraint in the table by its weight and add them up: the result is a lower limit on the objective that holds for every plan meeting the constraints. Our answer reaches that limit exactly, so no plan does better. Every step was checked in exact fractions, not rounded decimals.

#ConstraintWeight
3d ≥ -a - b + 21/4
6d ≥ a + 2·b - 21/2
7d ≥ -a - 3·b + 41/4

Algebraic model (low level)

Decision variables, objective and every constraint written out; this is exactly what the solver receives.

Standard form

As a linear program: minimize cᵀx subject to A x ≤ b (the inequality rows) and A_eq x = b_eq (the equations); a maximization is written as minimizing the negative.

Model code (cvxpy)

The same model in cvxpy, ready to run.

import cvxpy as cp

d = cp.Variable(name='d')  # largest absolute residual (y units)
a = cp.Variable(name='a')  # intercept of fitted line (y units)
b = cp.Variable(name='b')  # slope of fitted line (y per unit t), free sign

objective = cp.Minimize(d)
constraints = [
    d >= 1 - a,
    d >= a - 1,
    d >= -a - b + 2,
    d >= a + b - 2,
    d >= -a - 2*b + 2,
    d >= a + 2*b - 2,
    d >= -a - 3*b + 4,
    d >= a + 3*b - 4,
    d >= -a - 4*b + 5,
    d >= a + 4*b - 5,
    d >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('d =', d.value)
print('a =', a.value)
print('b =', b.value)

The dual problem

Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. Strong duality: primal and dual optima are equal (0.5).

Dual variablePricesValue
y1price of constraint 'd >= 1 - a' (objective change per extra unit of its right-hand side)0
y2price of constraint 'd >= a - 1' (objective change per extra unit of its right-hand side)0
y3price of constraint 'd >= -a - b + 2' (objective change per extra unit of its right-hand side)0.25
y4price of constraint 'd >= a + b - 2' (objective change per extra unit of its right-hand side)0
y5price of constraint 'd >= -a - 2*b + 2' (objective change per extra unit of its right-hand side)0
y6price of constraint 'd >= a + 2*b - 2' (objective change per extra unit of its right-hand side)0.5
y7price of constraint 'd >= -a - 3*b + 4' (objective change per extra unit of its right-hand side)0.25
y8price of constraint 'd >= a + 3*b - 4' (objective change per extra unit of its right-hand side)0
y9price of constraint 'd >= -a - 4*b + 5' (objective change per extra unit of its right-hand side)0
y10price of constraint 'd >= a + 4*b - 5' (objective change per extra unit of its right-hand side)0

Solve your own

This is the model as the app reads it. Change any number and solve it in the free box on the front page (no account needed).

minimize d
subject to
d >= 1 - (a + b*0)
d >= (a + b*0) - 1
d >= 2 - (a + b*1)
d >= (a + b*1) - 2
d >= 2 - (a + b*2)
d >= (a + b*2) - 2
d >= 4 - (a + b*3)
d >= (a + b*3) - 4
d >= 5 - (a + b*4)
d >= (a + b*4) - 5
d >= 0
# a = intercept of fitted line (y units)
# b = slope of fitted line (y per unit t), free sign
# d = largest absolute residual (y units)

Change the numbers and solve it

Checked: the app's answer matches the reference answer in our test set, which two solvers (HIGHS, CLARABEL) agree on. Built 2026-11-10.

Related examples

All 50 solved examples

Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.

What do you want to optimize?

Type the math, describe it in words, snap a photo or say it. ProvenDecisions builds the model, solves it, checks it and walks you through it.

One constraint per line, or separated by commas. Add integer: x, y or binary: z for whole-number decisions. LaTeX works too.

Try: