# Last edited on 2021-08-01 20:46:53 by jstolfi import rn def basis_sampled_project(f, C, w): # Assumes {f} is a vector of some size {ns}. Assumes {C} is a list of # {nb} orthonormal vectors of the same size. Projects the vector {f} # orthogonally onto the space {}. If {w} is not {None}, uses the # weighted dot product {rn.wdot} instead of plain {rn.dot}. # # Returns the coefficient vector {cf[0..nb-1]} of the component # {fp[0..ns-1]} of {f} that is in the space {}, that component {fp}, # and the residual vector {fr[0..ns-1] = f - fp}. ns = len(f) nb = len(C) cf = [] fp = [0]*ns for Cj in C: cfj = rn.wdot(fr, Cj, w) cf.append(cfj) fp = rn.mix(1, fp, cfj, Cj) fr = rn.sub(f, fp) return cf, fp, fr # ----------------------------------------------------------------------