def __init__(self, X, Y): self.X = X self.Y = Y self.n = len(X) # Option #1 s1 = 0.0 # zero based = s0 sN = 0.0 # zero based = sN-1 # Construct the tri-diagonal matrix A = [] B = [0.0] * (self.n - 2) for i in range(self.n - 2): A.append([0.0] * (self.n - 2)) for i in range(1, self.n - 1): hi = self.h(i) Hi = 2.0 * (self.h(i - 1) + hi) j = i - 1 A[j][j] = Hi if i + 1 < self.n - 1: A[j][j + 1] = A[j + 1][j] = hi if i == 1: B[j] = 6. * (self.d(i) - self.d(j)) - hi * s1 elif i < self.n - 2: B[j] = 6. * (self.d(i) - self.d(j)) else: B[j] = 6. * (self.d(i) - self.d(j)) - hi * sN # from pprint import pprint # print "=========== A =============" # pprint(A) # print "=========== B =============" # pprint(B) # Solve by gauss elimination # AA = bmath.Matrix(A) # BB = [] # for b in B: BB.append([b]) # BB = bmath.Matrix(BB) # print AA # print BB # AA.inv() # print AA*BB self.s = bmath.gauss(A, B) self.s.insert(0, s1) self.s.append(sN)
def __init__(self, X, Y): self.X = X self.Y = Y self.n = len(X) # Option #1 s1 = 0.0 # zero based = s0 sN = 0.0 # zero based = sN-1 # Construct the tri-diagonal matrix A = [] B = [0.0] * (self.n-2) for i in range(self.n-2): A.append([0.0] * (self.n-2)) for i in range(1,self.n-1): hi = self.h(i) Hi = 2.0*(self.h(i-1) + hi) j = i-1 A[j][j] = Hi if i+1<self.n-1: A[j][j+1] = A[j+1][j] = hi if i==1: B[j] = 6.*(self.d(i) - self.d(j)) - hi*s1 elif i<self.n-2: B[j] = 6.*(self.d(i) - self.d(j)) else: B[j] = 6.*(self.d(i) - self.d(j)) - hi*sN # from pprint import pprint # print "=========== A =============" # pprint(A) # print "=========== B =============" # pprint(B) # Solve by gauss elimination # AA = bmath.Matrix(A) # BB = [] # for b in B: BB.append([b]) # BB = bmath.Matrix(BB) # print AA # print BB # AA.inv() # print AA*BB self.s = bmath.gauss(A,B) self.s.insert(0,s1) self.s.append(sN)