Numerical integration: Difference between revisions
Content added Content deleted
(Added Kotlin) |
(→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details) |
||
Line 2,615: | Line 2,615: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
<lang scala>// version 1.1. |
<lang scala>// version 1.1.2 |
||
typealias Func = (Double) -> Double |
typealias Func = (Double) -> Double |
||
Line 2,630: | Line 2,630: | ||
sum[4] += (f(x) + 4.0 * f(x + h / 2.0) + f(x + h)) / 6.0 |
sum[4] += (f(x) + 4.0 * f(x + h / 2.0) + f(x + h)) / 6.0 |
||
} |
} |
||
val methods = listOf("LeftRect ", "MidRect ", "RightRect", "Trapezium", "Simpson ") |
val methods = listOf("LeftRect ", "MidRect ", "RightRect", "Trapezium", "Simpson ") |
||
for (i in 0..4) println("${methods[i]} = ${"%f".format(sum[i] * h)}") |
for (i in 0..4) println("${methods[i]} = ${"%f".format(sum[i] * h)}") |
||
println() |
println() |