Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun getK1(x: Double, t: Double): Double = func(x, t)
- fun getK2(x: Double, t: Double, h: Double): Double = func(x + h / 2 * getK1(x, t), t + h / 2)
- fun getK3(x: Double, t: Double, h: Double): Double =
- func(x + h / 4 * getK1(x, t) + h / 4 * getK2(x, t, h), t + h / 2)
- fun getK4(x: Double, t: Double, h: Double): Double = func(x - h * getK2(x, t, h) + 2 * h * getK3(x, t, h), t + h)
- fun getK5(x: Double, t: Double, h: Double): Double =
- func(x + h / 27 * (7 * getK1(x, t) + 10 * getK2(x, t, h) + getK4(x, t, h)), t + 2.0 / 3 * h)
- fun getK6(x: Double, t: Double, h: Double): Double =
- func(
- x + h / 625 * (28 * getK1(x, t) - 125 * getK2(x, t, h) + 546 * getK3(x, t, h) + 54 * getK4(
- x,
- t,
- h
- ) - 378 * getK5(x, t, h)),
- t + 1.0 / 5 * h
- )
- fun getDelta(x: Double, t: Double, h: Double) =
- h / 336 * (-42 * getK1(x, t) - 224 * getK3(x, t, h) - 21 * getK4(x, t, h) + 162 * getK5(
- x,
- t,
- h
- ) + 125 * getK6(x, t, h))
- fun compute4(x: Double, t: Double, h: Double) =
- 1.0 / 6 * (getK1(x, t) + 4 * getK3(x, t, h) + getK4(x, t, h)) // h**4
- fun compute5(x: Double, t: Double, h: Double) =
- 1.0 / 336 * (14 * getK1(x, t) + 35 * getK4(x, t, h) + 162 * getK5(x, t, h) + 125 * (getK6(x, t, h))) // h**5
- fun deltaGraph(x0: Double, t0: Double, T: Double, count: Int): Array<Double> {
- val h = (T - t0) / count;
- var t = t0;
- var x = x0
- var result = ArrayList<Double>()
- while (t < T) {
- t += h
- result.add(getDelta(x, t, h))
- x += h * compute4(x, t, h)
- }
- return result.toArray(Array<Double>(0) { 0.0 })
- }
- fun integrate4(x0: Double, t0: Double, T: Double, count: Int): Array<Double> {
- val h = (T - t0) / count;
- var t = t0;
- var x = x0
- var result = ArrayList<Double>()
- while (t < T) {
- x += h * compute4(x, t, h)
- t += h
- result.add(x)
- }
- return result.toArray(Array<Double>(0) { 0.0 })
- }
- fun integrate5(x0: Double, t0: Double, T: Double, count: Int): Array<Double> {
- val h = (T - t0) / count;
- var t = t0;
- var x = x0;
- var result = ArrayList<Double>()
- while (t < T) {
- x += h * compute5(x, t, h)
- t += h
- result.add(x)
- }
- return result.toArray(Array<Double>(0) { 0.0 })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement