Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.quantifind.charts.Highcharts._
- trait InitialVals {
- type CombinedResults = (List[Double], List[Double], List[Double])
- val U = (x: Double, y: Double) => scala.math.pow(x, 3) * scala.math.pow(y, 3)
- val F = (x: Double, y: Double) => 6 * x * scala.math.pow(y, 3) + 6 * y * scala.math.pow(x, 3)
- val Uij = (x: Double, y: Double, h: Double) =>
- ((1 / (h * h)) * (U(x + h, y) + U(x - h, y)) +
- (1 / (h * h)) * (U(x, y - h) + U(x, y + h)) - F(x, y)) / (4 / (h * h))
- }
- object Dirihle extends InitialVals {
- def perform(N: Double): CombinedResults = {
- val h = 1 / (N + 1)
- def innerProcessing(i: Double,
- x: Double,
- y: Double,
- accX: List[Double],
- accYp: List[Double],
- accY: List[Double]): CombinedResults = {
- if (x <= 1) innerProcessing(i + 1, i * h, i * h, accX :+ (i * h), accYp :+ U(x, y), accY :+ Uij(x, y, h))
- else (accX, accYp, accY)
- }
- innerProcessing(0, 0.0, 0.0, List[Double](), List[Double](), List[Double]())
- }
- }
- object Main extends App with InitialVals {
- val N = args(0).toInt
- val answer = Dirihle.perform(30)
- val resultX = answer._1.tail
- val resultYp = answer._2.tail
- val resultY = answer._3.tail
- println(resultX)
- line(resultX, resultYp)
- hold
- line(resultX, resultY)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement