---
url: https://marimo-team.github.io/marimo-studio/examples/quadratic-programs.md
description: >-
  Compare a lecture deck, a reading explainer, an interactive geometry lab, and
  a typeset report backed by one quadratic program notebook.
---

# Quadratic programs

[`quadratic_program.py`](https://github.com/marimo-team/marimo-studio/blob/main/examples/quadratic_program.py)
states a small quadratic program with [CVXPY](https://www.cvxpy.org/), a Python
library for convex optimization. It solves the program for four shapes of the
objective and every direction of its linear term. Cell by cell, the notebook
holds the argument of a short lesson: the standard form, why the problem
matters, its geometry, duality, and the key ideas. Every view reads its
results from these cells.

## Compare the views

**Lecture** is a [Reveal.js](https://revealjs.com/) deck. Each slide projects
one notebook cell or draws from the notebook's `region`, `bowl`, and `solution`
values. Step through the two-dimensional example to add the walls, the feasible
region, the level curves, and the solution in turn. On the next slide, change
the shape of *P* and the direction of *q* with the notebook's own controls.

**Explainer** is a single HTML page. Its reading column projects the notebook's
Markdown, while the figure, the solution summary, and a table of dual values stay
beside it. The native **Shape of P** and **Direction of q** controls select one
of 48 prepared notebook states.

**Lab** is a [Svelte](https://svelte.dev/) app drawn with
[D3](https://d3js.org/). Drag the handle around the dial, or scrub the value
curve beneath it, to turn *q*. The notebook's `sweep` records the solution for
180 directions, so the optimum, the level curves, the readout, and the active
walls update in the browser. **Shape of P** selects one of four prepared
states.

**Report** is a two-page worked example typeset with
[Typst](https://typst.app/) in the style of a short paper. It sets the standard
form and the example's data in math, embeds the notebook's own matplotlib
figures of the region and the direction sweep as vector graphics, and
tabulates each wall's slack and dual value. Run the notebook locally and change
**Shape of P** or **Direction of q** in Notebook, and Studio renders the PDF
again with the new solution.

Open **Notebook** to read the analysis the views share.

## Run locally

From the root of a clone set up as described in
[Run an example locally](index.md#run-an-example-locally):

```console
uv run marimo edit examples/quadratic_program.py --sandbox
```

Studio opens the Explainer, the notebook's default view. The Lecture and Lab
views build with the Deno toolchain supplied by `marimo-studio[deno]`, and they
and the Explainer load their fonts from jsDelivr. The Report compiles with the
Typst compiler from `marimo-studio[typst]` and its embedded fonts.

## Read the source

* [Notebook](https://github.com/marimo-team/marimo-studio/blob/main/examples/quadratic_program.py)
* [Lecture view](https://github.com/marimo-team/marimo-studio/tree/main/examples/studio/quadratic_program/lecture)
* [Explainer view](https://github.com/marimo-team/marimo-studio/tree/main/examples/studio/quadratic_program/explainer)
* [Lab view](https://github.com/marimo-team/marimo-studio/tree/main/examples/studio/quadratic_program/lab)
* [Report view](https://github.com/marimo-team/marimo-studio/tree/main/examples/studio/quadratic_program/report)

The notebook adapts the
[quadratic program notebook](https://github.com/marimo-team/learn/blob/main/optimization/04_quadratic_program.py)
from marimo's learn repository, published under the
[MIT License](https://github.com/marimo-team/learn/blob/main/LICENSE).
