LU decomposition of symetric pentadiagonal matrix

From , 3 Years ago, written in Python, viewed 226 times.
URL https://pastebin.vip/view/6dcb94fb
  1. ''' d,e,f = LUdecomp5(d,e,f).
  2.    LU decomposition of symetric pentadiagonal matrix
  3.    [f\e\d\e\f]. On output {d},{e} and {f} are the
  4.    diagonals of the decomposed matrix.
  5.  
  6.    x = LUsolve5(d,e,f,b).
  7.    Solves [f\e\d\e\f]{x} = {b}, where {d}, {e} and {f}
  8.    are the vectors returned from LUdecomp5.
  9.    '''
  10. def LUdecomp5(d,e,f):
  11.     n = len(d)
  12.     for k in range(n-2):
  13.         lam = e[k]/d[k]
  14.         d[k+1] = d[k+1] - lam*e[k]
  15.         e[k+1] = e[k+1] - lam*f[k]
  16.         e[k] = lam
  17.         lam = f[k]/d[k]
  18.         d[k+2] = d[k+2] - lam*f[k]
  19.         f[k] = lam
  20.     lam = e[n-2]/d[n-2]
  21.     d[n-1] = d[n-1] - lam*e[n-2]
  22.     e[n-2] = lam
  23.     return d,e,f
  24.  
  25. def LUsolve5(d,e,f,b):
  26.     n = len(d)
  27.     b[1] = b[1] - e[0]*b[0]
  28.     for k in range(2,n):
  29.         b[k] = b[k] - e[k-1]*b[k-1] - f[k-2]*b[k-2]
  30.  
  31.     b[n-1] = b[n-1]/d[n-1]
  32.     b[n-2] = b[n-2]/d[n-2] - e[n-2]*b[n-1]
  33.     for k in range(n-3,-1,-1):
  34.         b[k] = b[k]/d[k] - e[k]*b[k+1] - f[k]*b[k+2]
  35.     return b
  36. #//python/7413

Reply to "LU decomposition of symetric pentadiagonal matrix"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website