Polynomial regression: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) m (→{{header|11l}}) |
(→{{header|Kotlin}}: Fix polyRegression: x2m, x3m and x4m should use x, not r.) |
||
Line 1,067: | Line 1,067: | ||
fun polyRegression(x: IntArray, y: IntArray) { |
fun polyRegression(x: IntArray, y: IntArray) { |
||
val n = x.size |
|||
val r = 0 until n |
|||
val xm = x.average() |
val xm = x.average() |
||
val ym = y.average() |
val ym = y.average() |
||
val x2m = |
val x2m = x.map { it * it }.average() |
||
val x3m = |
val x3m = x.map { it * it * it }.average() |
||
val x4m = |
val x4m = x.map { it * it * it * it }.average() |
||
val xym = x.zip(y).map { it.first * it.second }.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() |
val x2ym = x.zip(y).map { it.first * it.first * it.second }.average() |
||
Line 1,092: | Line 1,090: | ||
println(" Input Approximation") |
println(" Input Approximation") |
||
println(" x y y1") |
println(" x y y1") |
||
for ( |
for ((xi, yi) in x zip y) { |
||
System.out.printf("%2d %3d %5.1f\n", |
System.out.printf("%2d %3d %5.1f\n", xi, yi, abc(xi)) |
||
} |
} |
||
} |
} |
||
fun main( |
fun main() { |
||
val x = IntArray(11) { it } |
val x = IntArray(11) { it } |
||
val y = intArrayOf(1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321) |
val y = intArrayOf(1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321) |