Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Euler-method/Kotlin/euler-method.kotlin
Normal file
32
Task/Euler-method/Kotlin/euler-method.kotlin
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// version 1.1.2
|
||||
|
||||
typealias Deriv = (Double) -> Double // only one parameter needed here
|
||||
|
||||
const val FMT = " %7.3f"
|
||||
|
||||
fun euler(f: Deriv, y: Double, step: Int, end: Int) {
|
||||
var yy = y
|
||||
print(" Step %2d: ".format(step))
|
||||
for (t in 0..end step step) {
|
||||
if (t % 10 == 0) print(FMT.format(yy))
|
||||
yy += step * f(yy)
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
fun analytic() {
|
||||
print(" Time: ")
|
||||
for (t in 0..100 step 10) print(" %7d".format(t))
|
||||
print("\nAnalytic: ")
|
||||
for (t in 0..100 step 10)
|
||||
print(FMT.format(20.0 + 80.0 * Math.exp(-0.07 * t)))
|
||||
println()
|
||||
}
|
||||
|
||||
fun cooling(temp: Double) = -0.07 * (temp - 20.0)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
analytic()
|
||||
for (i in listOf(2, 5, 10))
|
||||
euler(::cooling, 100.0, i, 100)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue