0

def LinearSpline(x, fx): #to determine the coefficients

'''

Valid call:
coeffs = LinearSpline(x, fx) Inputs:
x : (array) x values at which we have f(x) values. fx : (array) f(x)values associated with x values. Output:
coeffs : (array) coefficients of the linear spline. Assumption:
All inputs are given correctly. '''

nsegs = len(x)-1
A = np.zeros((2*nsegs, 2*nsegs))
b = np.zeros((2*nsegs, 1))

for i in range(nsegs):
    
    A[2*i, 2*i] = x[i]
    A[2*i, 2*i+1] = 1.0
    A[2*i+1, 2*i] = x[i+1]
    A[2*i+1, 2*i+1] = 1.0
    
    b[2*i] = fx[i]
    b[2*i+1] = fx[i+1]




# solve the system
coeffs = la.solve(A, b)

print(A)
print(b)

return coeffs

*I created a linear spline loop...need to also create a qudratic but is having trouble printing the "c" componet for the c coefficient....any help would be greatly appreciated

0 Answers0