Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. fun getK1(x: Double, t: Double): Double = func(x, t)
  2.  
  3. fun getK2(x: Double, t: Double, h: Double): Double = func(x + h / 2 * getK1(x, t), t + h / 2)
  4.  
  5. fun getK3(x: Double, t: Double, h: Double): Double =
  6. func(x + h / 4 * getK1(x, t) + h / 4 * getK2(x, t, h), t + h / 2)
  7.  
  8. fun getK4(x: Double, t: Double, h: Double): Double = func(x - h * getK2(x, t, h) + 2 * h * getK3(x, t, h), t + h)
  9.  
  10. fun getK5(x: Double, t: Double, h: Double): Double =
  11. func(x + h / 27 * (7 * getK1(x, t) + 10 * getK2(x, t, h) + getK4(x, t, h)), t + 2.0 / 3 * h)
  12.  
  13. fun getK6(x: Double, t: Double, h: Double): Double =
  14. func(
  15. x + h / 625 * (28 * getK1(x, t) - 125 * getK2(x, t, h) + 546 * getK3(x, t, h) + 54 * getK4(
  16. x,
  17. t,
  18. h
  19. ) - 378 * getK5(x, t, h)),
  20. t + 1.0 / 5 * h
  21. )
  22.  
  23. fun getDelta(x: Double, t: Double, h: Double) =
  24. h / 336 * (-42 * getK1(x, t) - 224 * getK3(x, t, h) - 21 * getK4(x, t, h) + 162 * getK5(
  25. x,
  26. t,
  27. h
  28. ) + 125 * getK6(x, t, h))
  29.  
  30. fun compute4(x: Double, t: Double, h: Double) =
  31. 1.0 / 6 * (getK1(x, t) + 4 * getK3(x, t, h) + getK4(x, t, h)) // h**4
  32.  
  33. fun compute5(x: Double, t: Double, h: Double) =
  34. 1.0 / 336 * (14 * getK1(x, t) + 35 * getK4(x, t, h) + 162 * getK5(x, t, h) + 125 * (getK6(x, t, h))) // h**5
  35.  
  36. fun deltaGraph(x0: Double, t0: Double, T: Double, count: Int): Array<Double> {
  37. val h = (T - t0) / count;
  38. var t = t0;
  39. var x = x0
  40. var result = ArrayList<Double>()
  41. while (t < T) {
  42. t += h
  43. result.add(getDelta(x, t, h))
  44. x += h * compute4(x, t, h)
  45. }
  46.  
  47. return result.toArray(Array<Double>(0) { 0.0 })
  48. }
  49.  
  50. fun integrate4(x0: Double, t0: Double, T: Double, count: Int): Array<Double> {
  51. val h = (T - t0) / count;
  52. var t = t0;
  53. var x = x0
  54. var result = ArrayList<Double>()
  55.  
  56. while (t < T) {
  57. x += h * compute4(x, t, h)
  58. t += h
  59. result.add(x)
  60. }
  61.  
  62. return result.toArray(Array<Double>(0) { 0.0 })
  63. }
  64.  
  65. fun integrate5(x0: Double, t0: Double, T: Double, count: Int): Array<Double> {
  66. val h = (T - t0) / count;
  67. var t = t0;
  68. var x = x0;
  69. var result = ArrayList<Double>()
  70.  
  71. while (t < T) {
  72. x += h * compute5(x, t, h)
  73. t += h
  74. result.add(x)
  75. }
  76. return result.toArray(Array<Double>(0) { 0.0 })
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement