Programmer
Programmer

Reputation: 161

Overflow error when solving banded simultaneous equation

I am trying to solve the banded simultaneous equation using the function from the computational physics book: http://www-personal.umich.edu/~mejn/cp/programs/banded.py However, running the function causes an overflow error of:

OverflowError: cannot convert float infinity to integer in banded line 39: v[m] /= div

The matrix A and w are:

A = 
[[ 3 -1 -1 ...  0  0  0]
 [-1  4 -1 ...  0  0  0]
 [-1 -1  4 ...  0  0  0]
 ...
 [ 0  0  0 ...  4 -1 -1]
 [ 0  0  0 ... -1  4 -1]
 [ 0  0  0 ... -1 -1  3

w = [5 5 0 ... 0 0 0]

x = banded(A,w,2,2)

Can someone help me figure out why there is an overflow error when using this function? Thank you.

Upvotes: 1

Views: 70

Answers (1)

HinnyTsang
HinnyTsang

Reputation: 26

I think you should make A into a banded matrix as shown in banded.py

(  -   -  A02 A13 A24 ...
(  -  A01 A12 A23 A34 ...
( A00 A11 A22 A33 A44 ...
( A10 A21 A32 A43 A54 ...
( A20 A31 A42 A53 A64 ...

Besides, I find that the banded function would not work properly if the matrix elements in either matrix A or vector w is an integer, you may consider to initialize it into a float.

Upvotes: 1

Related Questions