5.4.10 · D1Scientific Computing (Python)

Foundations — scipy.optimize — minimize, fsolve, curve_fit, linprog

1,953 words9 min readBack to topic

This page assumes nothing. If the parent note wrote a symbol, we build it here from a picture first. Read top to bottom — each idea is the floor the next one stands on.


0 · What is a "function" here, as a picture?

Before any fancy symbol, fix the mental image.

Figure — scipy.optimize — minimize, fsolve, curve_fit, linprog

Look at the figure. The horizontal axis is where you stand (). The curve's height above each point is the value . The red dot marks the lowest point — the minimum. Everything in this whole topic is a hunt for special points on such a map.


1 · The vector — standing in more than one dimension

The parent writes with a bold . Why bold?

Figure — scipy.optimize — minimize, fsolve, curve_fit, linprog

In the figure the arrow points from the origin to the position . Now the height map lives above the whole floor, like a real hill over a field. The parent's bowl is exactly such a hill in 2D.


2 · Slope in 1D: the derivative

To go downhill you must know which way tilts down. In 1D that tilt is the derivative.

The notation (read "f prime") and its cousin mean the same thing: slope of with respect to .


3 · Slope in many dimensions: the gradient

On a field (2D) there isn't one slope — the ground tilts differently as you face different ways. We need a slope per coordinate.

Figure — scipy.optimize — minimize, fsolve, curve_fit, linprog

The symbol ("partial") is just done one coordinate at a time, holding the others frozen. Look at the figure: red arrows are the gradient at several points, always pointing away from the low centre. At the very bottom the arrow shrinks to nothing.


4 · Curvature: the second derivative and the Hessian

Flat isn't enough. Is the flat spot a valley (curves up) or a peak (curves down)?

You don't need to compute a Hessian by hand here; you need the picture: gradient tells you which way to step, curvature tells you how far and whether you've found a true bottom. Newton's method (parent's engine) uses both.


5 · Roots and the symbol

fsolve doesn't minimize — it hunts for crossings.


6 · The Jacobian — the gradient's big brother

When is a list of functions, its slope is a grid of slopes.

You only need to recognise the word: when the parent writes , that is "one Newton step for a system" — no new idea, just the plural of a slope.


7 · Data, residuals, and the symbol

curve_fit bends a model curve toward scattered dots.

Figure — scipy.optimize — minimize, fsolve, curve_fit, linprog

The red segments in the figure are the residuals. The subscript just means "the -th dot". The symbol ("sigma") means add up over all dots:

The parameters we tune are bundled as (bold "theta") — the list of knobs (like in ) we're free to turn.


8 · Linear objectives and the corner idea

linprog's symbols are the tamest — everything is a straight line or flat plane.


How these foundations feed the topic

Function as height map

Derivative slope

Vector position x

Gradient del f

Stationary point del f = 0

Curvature f'' and Hessian

minimize

Newtons Method

Jacobian for systems

fsolve

Residuals and sum of squares

curve_fit

Linear objective c x

linprog corners

Read it downward: the plain height-map idea splits into slope and position; those merge into the gradient; the gradient being zero is what every engine hunts for.


Equipment checklist

Cover the right side and test yourself. If any answer is fuzzy, reread that section before the parent note.

What does return, in picture terms?
A single height above the point on a landscape.
Why is written in bold?
It is a list of coordinates — a position in possibly many dimensions, not one number.
What does the derivative measure?
The steepness/tilt of the curve — how fast height changes as you nudge .
What does mean geometrically?
The ground is momentarily flat — a candidate lowest (or highest) point.
What is the gradient as a picture?
An arrow on the floor pointing in the steepest-uphill direction; downhill is .
Why is minimizing the same as finding a root of ?
Because a minimum is a flat spot, and flat means — a zero (root) of the gradient.
What extra info does curvature ( / Hessian) give?
Whether a flat spot curves up (minimum), down (maximum), or is a saddle.
Why do we rewrite an equation as "something " for fsolve?
fsolve only finds where its function returns zero, so we move all terms to one side.
What is a residual ?
The vertical gap between a data point and the model's prediction.
Why square the residuals before summing?
So positive and negative misses don't cancel, giving an honest total error.
Why does a linear program's optimum sit at a corner?
A linear objective never flattens inside the region, so you slide along walls until a vertex stops you.