fit function
The least-squares fit of a combination of functions through points.
How to write it
fit(points, basis, x)
The combination whose squared distances to the points add up the least.
- points
- The points, as a list of pairs [x, y]. Takes a list.
- basis
- The functions to combine, in x, such as [1, x, x^2]. Takes a list.
- x
- The variable of the basis. Takes a variable.
fit(points, basis, x, distance = 1|2|inf)
The combination whose deviations from the points are least in that distance, when exactly one combination is.
- points
- The points, as a list of pairs [x, y]. Takes a list.
- basis
- The functions to combine, in x, such as [1, x, x^2]. Takes a list.
- x
- The variable of the basis. Takes a variable.
- distance = 1|2|inf
- Which deviations count: 1 their sum, 2 the sum of their squares (the default), inf the largest.
Examples
fit([[0, 1], [1, 3], [2, 5], [3, 8]], [1, x], x)In the solver,
Open in the solverfit([[0, 1], [1, 3], [2, 5], [3, 8]], [1, x], x)gives23x/10 + 4/5.fit([[0, 1], [1, 3], [2, 5], [3, 8]], [1, x, x^2], x)In the solver,
Open in the solverfit([[0, 1], [1, 3], [2, 5], [3, 8]], [1, x, x^2], x)givesx^2/4 + 31x/20 + 21/20.fit([[0, 0], [1, 1], [2, 2], [3, 3], [4, 10]], [1, x], x, distance = 1)In the solver,
Open in the solverfit([[0, 0], [1, 1], [2, 2], [3, 3], [4, 10]], [1, x], x, distance = 1)givesx.fit([[0, 0], [1, 1], [2, 2], [3, 3], [4, 10]], [1, x], x, distance = inf)In the solver,
Open in the solverfit([[0, 0], [1, 1], [2, 2], [3, 3], [4, 10]], [1, x], x, distance = inf)gives5x/2 - 9/4.
Related functions
- geometric_brownian_motion_process
A process that grows at rate mu with relative noise sigma, started at x0.
- exponential_distribution
The waiting time for events that come at rate lambda.
- geometric_sde_path
The path of dX = mu X dt + sigma X dW, as a function of the Wiener process's value w at time t.
- expectation
The expected value of an expression of a variable with a distribution or a process.
- ito_formula
Itô's lemma: the differential of an expression of states that follow an Itô process.
- distributed
A variable and the distribution it follows, as probability and expectation read it.