# function [ya] = interpolant_with_hat_function_basis(x,xi,yi) # # Accompanying program for the text # # Classical and Modern Numerical Analysis: # Theory, Methods and Practice # by Azmy S. Ackleh, Edward J. Allen, # R. Baker Kearfott, and Padmanabhan Seshaiyer # # (Taylor and Francis / CRC Press, 2009) # # y = piecewise_linear_interpolant_value (x, xi, yi) returns the # vector of values of the piecewise linear interpolant at corresponding # coordinates of the vector x, corresponding to the data set whose # abscissas are in the vector xi and whose ordinates are in the vector yi. # The size of x and the size of xi should correspond exactly to the number # of points to plot and the number of abscissas, respectively. # # For this implementation, the abscissas xi must be equally spaced. (This # function can be generalized so this is not a requirement.) import numpy as np from hat_function_value import hat_function_value def interpolant_with_hat_function_basis(x,xi,yi): m = len(x) n = len(xi)-1 h = (xi[-1] - xi[0]) / n ya = np.empty_like(x) for i in range(m): s = 0 for j in range(n+1): s += yi[j] * hat_function_value(j,xi,n,h,x[i]) ya[i] = s return ya