import { Mean } from "./Mean" ; interface Point { x : number ; y : number ; } param { Array < number > } . . a param { Array < number > } . . b param { number } n return { Array < any > } function LeastSquare ( [ ... a ] , [ ... b ] , n ) { if ( a instanceof Array && b instanceof Array ) { let __x__ = Mean ( a ) ; let __y__ = Mean ( b ) ; var total_1 = 0 , total_2 = 0 , _a_ , _b_ , y_ , temp = [ ] ; if ( a . length != b . length ) { throw TypeError ( "两个数组数据不符合" ) ; } for ( let i = 0 ; i < a . length ; i ++ ) { total_1 = a [ i ] * b [ i ] - ( a . length * __x__ * __y__ ) ; total_2 = a [ i ] ** 2 - ( a . length * __x__ ** 2 ) ; } _b_ = total_1 / total_2 ; _a_ = __y__ - _b_ * __x__ ; for ( let j = 1 ; j < n ; j ++ ) { y_ = _b_ * j + _a_ ; temp . push ( { x : j , y : y_ } ) ; } return temp ; } else { throw TypeError ( "参数必须是数组类型数据" ) ; } } export { LeastSquare } ;