Advertisement
Guest User

Lab3

a guest
May 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.28 KB | None | 0 0
  1. import com.quantifind.charts.Highcharts._
  2.  
  3. trait InitialVals {
  4.   type CombinedResults = (List[Double], List[Double], List[Double])
  5.   val U = (x: Double, y: Double) => scala.math.pow(x, 3) * scala.math.pow(y, 3)
  6.   val F = (x: Double, y: Double) => 6 * x * scala.math.pow(y, 3) + 6 * y * scala.math.pow(x, 3)
  7.   val Uij = (x: Double, y: Double, h: Double) =>
  8.         ((1 / (h * h)) * (U(x + h, y) + U(x - h, y)) +
  9.         (1 / (h * h)) * (U(x, y - h) + U(x, y + h)) - F(x, y)) / (4 / (h * h))
  10. }
  11.  
  12. object Dirihle extends InitialVals {
  13.   def perform(N: Double): CombinedResults = {
  14.     val h = 1 / (N + 1)
  15.  
  16.     def innerProcessing(i: Double,
  17.       x: Double,
  18.       y: Double,
  19.       accX: List[Double],
  20.       accYp: List[Double],
  21.       accY: List[Double]): CombinedResults = {
  22.       if (x <= 1) innerProcessing(i + 1, i * h, i * h, accX :+ (i * h), accYp :+ U(x, y), accY :+ Uij(x, y, h))
  23.       else (accX, accYp, accY)
  24.         }
  25.  
  26.     innerProcessing(0, 0.0, 0.0, List[Double](), List[Double](), List[Double]())
  27.   }
  28. }
  29.  
  30. object Main extends App with InitialVals {
  31.   val N = args(0).toInt
  32.   val answer = Dirihle.perform(30)
  33.   val resultX = answer._1.tail
  34.   val resultYp = answer._2.tail
  35.   val resultY = answer._3.tail
  36.  
  37.   println(resultX)
  38.   line(resultX, resultYp)
  39.   hold
  40.   line(resultX, resultY)
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement