Guest User

Untitled

a guest
Nov 9th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from math import cos, sin, pow, pi
  2. from numpy import zeros, array
  3.  
  4.  
  5. class Solution:
  6.  
  7.     def __init__(self, n, x, y):
  8.         self._n = n
  9.         self._uright = zeros((n + 1, n + 1))
  10.         self._u = zeros((n + 1, n + 1))
  11.         self.CalcURight(x, y)
  12.         #self._u.copy(list(self._uright))
  13.  
  14.     def CalcURight(self, x, y):
  15.         for i in range(0, self._n + 1):
  16.             for j in range(0, self._n + 1):
  17.                     self._uright[i][j] = sin(pi * x[i]) * sin(pi * y[j])
  18.  
  19.     def URight(self):
  20.         return self._uright
  21.  
  22.     def CalcURelax(self, h, w, u, f):
  23.         for i in range(1, self._n - 1):
  24.             for j in range(1, self._n - 1):
  25.                 one = (pow(h, 2) * w * f[i][j]) / 4
  26.                 two = w / 4 * (self._u[i - 1][j] + self._u[i][j - 1] + self._u[i + 1][j] + self._u[i][j + 1])
  27.                 three = (1 - w) * self._u[i][j]
  28.                 self._u[i][j] = one + two + three
  29.  
  30.     def U(self):
  31.         return self._u
Advertisement
Add Comment
Please, Sign In to add comment