image.png

In [4]:
u,v = 0,0
print(u,v)
for k in range(50):
    u,v = (5-v)/3, (6-u)/2
    print(k,u,v)
0 0
0 1.6666666666666667 3.0
1 0.6666666666666666 2.1666666666666665
2 0.9444444444444445 2.6666666666666665
3 0.7777777777777778 2.5277777777777777
4 0.8240740740740741 2.611111111111111
5 0.7962962962962963 2.587962962962963
6 0.8040123456790124 2.601851851851852
7 0.7993827160493826 2.5979938271604937
8 0.8006687242798355 2.6003086419753085
9 0.7998971193415638 2.5996656378600824
10 0.8001114540466392 2.600051440329218
11 0.799982853223594 2.59994427297668
12 0.8000185756744399 2.600008573388203
13 0.7999971422039324 2.59999071216278
14 0.80000309594574 2.6000014288980338
15 0.7999995237006554 2.5999984520271298
16 0.8000005159909568 2.600000238149672
17 0.7999999206167759 2.5999997420045218
18 0.8000000859984927 2.600000039691612
19 0.7999999867694627 2.5999999570007537
20 0.8000000143330821 2.600000006615269
21 0.7999999977949104 2.599999992833459
22 0.800000002388847 2.600000001102545
23 0.799999999632485 2.5999999988055764
24 0.8000000003981412 2.6000000001837575
25 0.7999999999387475 2.5999999998009296
26 0.8000000000663569 2.6000000000306263
27 0.7999999999897912 2.5999999999668217
28 0.8000000000110594 2.6000000000051045
29 0.7999999999982985 2.5999999999944703
30 0.8000000000018432 2.6000000000008505
31 0.7999999999997165 2.5999999999990786
32 0.8000000000003071 2.6000000000001418
33 0.7999999999999527 2.5999999999998464
34 0.8000000000000512 2.6000000000000236
35 0.7999999999999922 2.5999999999999743
36 0.8000000000000086 2.600000000000004
37 0.7999999999999986 2.5999999999999956
38 0.8000000000000015 2.6000000000000005
39 0.7999999999999998 2.599999999999999
40 0.8000000000000003 2.6
41 0.7999999999999999 2.5999999999999996
42 0.8000000000000002 2.6
43 0.7999999999999999 2.6
44 0.7999999999999999 2.6
45 0.7999999999999999 2.6
46 0.7999999999999999 2.6
47 0.7999999999999999 2.6
48 0.7999999999999999 2.6
49 0.7999999999999999 2.6
In [ ]:
Reminder about iteration, spectral radius of matrix.

image.png

In [5]:
# jacobi iteration

import numpy as np
import matplotlib.pyplot as plt

np.set_printoptions(linewidth=200)
M = 4
N = 6

w = np.zeros((M+1,N+1))

# BCs
w[-1,-4:-1] = 100
print(w)
print

for k in range(5):
        w[1:-1,1:-1] = ( w[0:-2,1:-1] + w[2:,1:-1] + w[1:-1,0:-2] + w[1:-1,2:] ) / 4
        print(w)
        print
[[  0.   0.   0.   0.   0.   0.   0.]
 [  0.   0.   0.   0.   0.   0.   0.]
 [  0.   0.   0.   0.   0.   0.   0.]
 [  0.   0.   0.   0.   0.   0.   0.]
 [  0.   0.   0. 100. 100. 100.   0.]]
[[  0.   0.   0.   0.   0.   0.   0.]
 [  0.   0.   0.   0.   0.   0.   0.]
 [  0.   0.   0.   0.   0.   0.   0.]
 [  0.   0.   0.  25.  25.  25.   0.]
 [  0.   0.   0. 100. 100. 100.   0.]]
[[  0.     0.     0.     0.     0.     0.     0.  ]
 [  0.     0.     0.     0.     0.     0.     0.  ]
 [  0.     0.     0.     6.25   6.25   6.25   0.  ]
 [  0.     0.     6.25  31.25  37.5   31.25   0.  ]
 [  0.     0.     0.   100.   100.   100.     0.  ]]
[[  0.       0.       0.       0.       0.       0.       0.    ]
 [  0.       0.       0.       1.5625   1.5625   1.5625   0.    ]
 [  0.       0.       3.125    9.375   12.5      9.375    0.    ]
 [  0.       1.5625   7.8125  37.5     42.1875  35.9375   0.    ]
 [  0.       0.       0.     100.     100.     100.       0.    ]]
[[  0.         0.         0.         0.         0.         0.         0.      ]
 [  0.         0.         1.171875   2.734375   3.90625    2.734375   0.      ]
 [  0.         1.171875   4.296875  13.671875  15.625     12.5        0.      ]
 [  0.         1.953125  10.546875  39.84375   46.484375  37.890625   0.      ]
 [  0.         0.         0.       100.       100.       100.         0.      ]]
[[  0.           0.           0.           0.           0.           0.           0.        ]
 [  0.           0.5859375    1.7578125    4.6875       5.2734375    4.1015625    0.        ]
 [  0.           1.5625       6.640625    15.625       19.140625    14.0625       0.        ]
 [  0.           2.9296875   11.5234375   42.67578125  48.33984375  39.74609375   0.        ]
 [  0.           0.           0.         100.         100.         100.           0.        ]]
In [ ]: