hypot

hypot(a, b, c, ...)

hypot([a, b, c, ...])

Try it yourself:

See also:

Find a Euclidean length with hypot

hypot(a, b, c, ...) returns the square root of the sum of squared inputs. For two values, it is the hypotenuse length sqrt(a^2 + b^2); for more values, it gives the Euclidean length in higher dimensions.

Examples

hypot(3, 4) is 5. This is useful for distance from coordinate differences: subtract coordinates with subtract, then pass the differences to hypot. For a vector already stored as a matrix, norm is often the more direct expression.

Numerical advantages

Hypot is generally preferable to manually squaring and summing because it can use a stable implementation that reduces overflow and underflow risk. Compare sqrt when you specifically need a square root of one value, and distance for a direct point-to-point operation.

Inputs

Inputs should be numeric and share meaningful units. A negative component is fine because it is squared; a nonnumeric value is not. Very large or very small values still deserve attention when interpreting precision.

All functions