3

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 Answers1

2

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)
Busti
  • 5,492
  • 2
  • 21
  • 34
bottaio
  • 4,963
  • 3
  • 19
  • 43