Runge-Kutta method: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 2,152:
=={{header|Scala}}==
<lang scala>object Main extends App {
val f = (tnt: Double, yny: Double) => tnt * Math.sqrt(yny) // Runge-Kutta solution
val g = (t: Double) => Math.pow(t * t + 4, 2) / 16 // Exact solution
new Calculator(f, Some(g)).compute(100, 0, .1, 1)
}
Line 2,164:
f" Error: $err%7.5e"
}
val s = g.map(c(_)).getOrElse((x: Double) => ".") // If we don't have exact solution, just print a period dot "."
println(f"y($tn%4.1f) = $yn%12.8f${s(tn)}")
}
Anonymous user