gpt4 book ai didi

scala - 使用 nth 的二维插值

转载 作者:行者123 更新时间:2023-12-02 00:59:25 26 4
gpt4 key购买 nike

假设我有 2 个数组

 x = [1,2,3,4,5,6]
y = [4,53,234,43,12,2]

n 的多项式拟合 y = F(x)。如何从 x 内插 y

最佳答案

可以使用 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)

关于scala - 使用 nth 的二维插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51659166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com