假设我有2个数组
x = [1,2,3,4,5,6]
y = [4,53,234,43,12,2]
适合n
的度数y = F(x)
的多项式。如何从x内插y
答案 0 :(得分:2)
一个人可以使用Apache Commons Math。这是一个例子
import scala.collection.JavaConverters._
val x = 1 to 6
val y = Array(4, 53, 234, 43, 12, 2)
val n = 5
val fitter = PolynomialCurveFitter.create(n)
val result = fitter.fit((x zip y).map { case (a, b) =>
new WeightedObservedPoint(1, a, b)
}.asJava)
println(result.toList)