Skip to content

Quadratic programs ​

quadratic_program.py states a small quadratic program with CVXPY, 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 ​

Loading…
ReactReveal.js Source

Lecture is a Reveal.js 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 app drawn with D3. 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 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:

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 ​

The notebook adapts the quadratic program notebook from marimo's learn repository, published under the MIT License.