linefit()

Description:

Perform linear fitting using the least squares method.

Syntax:

linefit(A,Y)

Note:

A least squares fitting technique is to get the nearest possible value of constant sequence/ vector Y by multiplying matrix A by vector X, that is, the nearest result of AX=Y. The function performs a linear fitting using the least squares method to get vector X. The function returns a matrix when parameter Y is a matrix and a vector when Y is a vector.

Parameter:

A

A matrix or a vector

Y

A matrix or a vector

Return value:

Sequence

Example:

 

A

 

1

[[1,2,3,4],[2,3,1,2],[1,1,1,-1],[1,0,-2,-6]]

 

2

[[2,2],[3,5,1],[8],[4]]

 

3

=linefit(A1,A2)

 

Fit A1 and A2 together using the least squares fitting technique and return the fitting coefficient.

4

[4,6,-2,4]

 

5

=linefit(A1,A4)

Fit A1 and A4 together using the least squares fitting technique and return the fitting coefficient.