Skip to content

Statistics and data

The mean of all the numbers given.

mean([1; 2; 3; 6]) = 3

The median of all the numbers given.

median([1; 2; 3; 6]) = 2.5

The variance of the numbers as a whole population (dividing by n).

var([1; 2; 3; 6]) = 3.5

The variance of the numbers as a sample (dividing by n − 1).

Var([1; 2; 3; 6]) = 4.667

The standard deviation of a whole population.

stdev([1; 2; 3; 6]) = 1.871

The standard deviation of a sample.

Stdev([1; 2; 3; 6]) = 2.16

The correlation coefficient of the two vectors.

corr([1; 2; 3], [2; 4; 7]) = 0.993

The slope of the least-squares straight line through the points.

slope([1; 2; 3], [2; 4; 7]) = 2.5

Where the least-squares straight line crosses x = 0.

intercept([1; 2; 3], [2; 4; 7]) = -0.667

The value at x of the straight lines between the points (vx, vy); beyond the ends, the end line carries on.

linterp([0 m; 2 m], [10 kN; 20 kN], 0.5 m) = 12.5 kN

A cubic spline through the points, with cubic ends, for interp.

vx := [0; 1; 2; 3]
vy := vx^3
interp(cspline(vx, vy), vx, vy, 1.5) = 3.375

A cubic spline with parabolic ends, for interp.

vx := [0; 1; 2; 3]
vy := [0; 1; 4; 9]
interp(pspline(vx, vy), vx, vy, 1.5) = 2.25

A cubic spline with straight ends (the natural spline), for interp.

vx := [0; 1; 2; 3]
vy := [0; 1; 4; 9]
interp(lspline(vx, vy), vx, vy, 1.5) = 2.2

The value at x of a spline from cspline, pspline or lspline, or of a polynomial from regress.

vx := [0; 1; 2; 3]
vy := [1; 3; 5; 7]
interp(regress(vx, vy, 1), vx, vy, 10) = 21

The least-squares polynomial of degree k through the points, for interp.

vx := [0; 1; 2; 3]
vy := [1; 2; 5; 10]
interp(regress(vx, vy, 2), vx, vy, 4) = 17

The least-squares coefficients of a sum of terms: F(x) returns a vector of the terms.

F(x) := [1; x]
linfit([0; 1; 2], [1; 3; 5], F) = [1; 2]

The probability density of the normal distribution at x.

dnorm(0, 0, 1) = 0.399

The probability that a normal variable is below x.

pnorm(1.96, 0, 1) = 0.975

The probability that a standard normal variable is below x.

cnorm(1.645) = 0.95

The x below which a normal variable falls with probability p.

qnorm(0.95, 0, 1) = 1.645

A random number between 0 and x, the same at every recalculation.

rnd(1) = 0.731

m random numbers between a and b, as a column.

runif(3, 0, 10) = [7.309; 4.101; 2.077]

m random numbers from the normal distribution, as a column.

rnorm(3, 0, 1) = [1.562; -0.608; -1.091]

How many of the data fall in each interval: intervals is a vector of their ends, or the number of equal intervals.

hist([0; 1; 2; 3], [0.5; 1.5; 1.7; 2.2]) = [1; 2; 1]

As hist, beside the middle of each interval: a column of middles, then one of counts.

histogram([0; 1; 2; 3], [0.5; 1.5; 1.7; 2.2]) = [0.5, 1; 1.5, 2; 2.5, 1]

The Fourier transform of the real vector v (2ⁿ elements), its first half and the middle, scaled by 1/√n.

fft([1; 0; 0; 0]) = [0.5; 0.5; 0.5]

The inverse of fft: the real vector whose transform is c.

ifft(fft([1; 2; 3; 4])) = [1; 2; 3; 4]

As fft, scaled by 1/n and with the opposite sign in the exponent.

FFT([1; 0; 0; 0]) = [0.25; 0.25; 0.25]

The inverse of FFT.

IFFT(FFT([1; 2; 3; 4])) = [1; 2; 3; 4]

The Fourier transform of a complex vector or matrix of any size, scaled by 1/√n.

cfft([1; 1i]) = [0.707 + 0.707i; 0.707 - 0.707i]

The inverse of cfft.

icfft(cfft([1; 1i])) = [1; 1i]

As cfft, scaled by 1/n and with the opposite sign in the exponent.

CFFT([1; 1i]) = [0.5 + 0.5i; 0.5 - 0.5i]

The inverse of CFFT.

ICFFT(CFFT([1; 1i])) = [1; 1i]

The numbers in a text file, in columns separated by spaces, tabs or commas; lines that aren’t numbers are skipped.

A comma-separated file as a matrix, numbers and text kept apart.

A data file, type being “delimited” (spaces, tabs or commas) or “csv”.

The cells of an Excel workbook (.xlsx or .xls), all of its first sheet or a range; in the desktop app.