Polynomial regression: Difference between revisions

→‎{{header|Kotlin}}: Fix polyRegression: x2m, x3m and x4m should use x, not r.
(→‎{{header|Kotlin}}: Fix polyRegression: x2m, x3m and x4m should use x, not r.)
Line 1,067:
 
fun polyRegression(x: IntArray, y: IntArray) {
val n = x.size
val r = 0 until n
val xm = x.average()
val ym = y.average()
val x2m = rx.map { it * it }.average()
val x3m = rx.map { it * it * it }.average()
val x4m = rx.map { it * it * it * it }.average()
val xym = x.zip(y).map { it.first * it.second }.average()
val x2ym = x.zip(y).map { it.first * it.first * it.second }.average()
Line 1,092 ⟶ 1,090:
println(" Input Approximation")
println(" x y y1")
for (i(xi, yi) in 0x untilzip ny) {
System.out.printf("%2d %3d %5.1f\n", x[i]xi, y[i]yi, abc(x[i]xi))
}
}
 
fun main(args: Array<String>) {
val x = IntArray(11) { it }
val y = intArrayOf(1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321)
Anonymous user