2D Interpolation using nth

199 Views Asked by At

Let's say I have 2 arrays

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

Polynomial of degree n to fit y = F(x). How to interpolate y from x

1

There are 1 best solutions below

0
On

One can use Apache Commons Math. Here's an example

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)