∇ProvenDecisions
Ctrl K

Ridge regression: a quadratic programming example, solved and checked

The ridge regression is a classic quadratic programming problem. Here it is solved by a real solver (CLARABEL) and checked: every constraint, the dual, and the optimality certificate. Change the numbers below and solve your own.

Answer. The smallest objective value is 1.46154, at x0 = 0.769231, x1 = 0.923077. All 2 constraints are satisfied exactly. Optimal, numerically checked.

Solve your own version free, no account needed

The problem

Minimize ||Ax - b||^2 + 0.5 ||x||^2 with A = [[1, 0], [1, 1], [1, 2], [1, 3]] and b = (1, 2, 2, 4).

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
intercept coefficient (unitless) is at least -1000
slope coefficient (unitless) is at least -1000

In matrix form

With its numbers:

What is being decided

There are 2 decision variables.

VariableTypeMeaning
x0real numberintercept coefficient (unitless)
x1real numberslope coefficient (unitless)

Goal and limits

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

Problem type

Convex QP, complexity level 1: a small convex quadratic. Solved with CLARABEL at the Medium solver tier.

Picture

Shaded: every point that satisfies all the constraints. Dot: the optimum. Dashed: the objective's level line through it.

(0.769231, 0.923077)-1200.15-1200.18-849.885-849.862-499.615-499.538-149.346-149.215200.923201.108x0x1

The answer at a glance

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

x00.769231x10.923077

Which constraints hold the answer in place

No constraint is binding. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1x0 >= -10000.769231-10001000.77
2x1 >= -10000.923077-10001000.92

Algebraic model (low level)

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

Model code (cvxpy)

The same model in cvxpy, ready to run.

import cvxpy as cp

x0 = cp.Variable(name='x0')  # intercept coefficient (unitless)
x1 = cp.Variable(name='x1')  # slope coefficient (unitless)

objective = cp.Minimize(0.5*x0**2 + 0.5*x1**2 + (x0 - 1)**2 + (x0 + x1 - 2)**2 + (x0 + 2*x1 - 2)**2 + (x0 + 3*x1 - 4)**2)
constraints = [
    x0 >= -1000,
    x1 >= -1000,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='CLARABEL')
print(problem.status, problem.value)
print('x0 =', x0.value)
print('x1 =', x1.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 (1.46154).

Dual variablePricesValue
y1multiplier of an inequality constraint0
y2multiplier of an inequality constraint0

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 (x0 + 0*x1 - 1)^2 + (x0 + x1 - 2)^2 + (x0 + 2*x1 - 2)^2 + (x0 + 3*x1 - 4)^2 + 0.5*(x0^2 + x1^2)
subject to
x0 >= -1000
x1 >= -1000
# x0 = intercept coefficient (unitless)
# x1 = slope coefficient (unitless)

Change the numbers and solve it

Checked: the app's answer matches the reference answer in our test set, which two solvers (CLARABEL, OSQP) 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: