def naive(f, s, Omega, N=10): psi = [] for i in range(N + 1): psi.append(sym.sin((2 * i + 1) * x)) u, c = least_squares_orth(f, psi, Omega, symbolic=False) comparison_plot(f, u, Omega, 'tmp_sin%02dx' % i, legend_loc='upper left', show=True)
def efficient(f, s, Omega, N=10): u = 0 for i in range(N + 1): psi = [sym.sin((2 * i + 1) * x)] next_term, c = least_squares_orth(f, psi, Omega, False) u = u + next_term comparison_plot(f, u, Omega, 'tmp_sin%02dx' % i, legend_loc='upper left', show=False, plot_title='s=%g, i=%d' % (s, i))
def efficient(f, B, s, Omega, N=10, basis='a'): u = B for i in range(N+1): if basis == 'a': psi = [sym.sin((i+1)*x)] elif basis == 'b': psi = [sym.sin((2*i+1)*x)] elif basis == 'c': psi = [sym.sin(2*(i+1)*x)] next_term, c = least_squares_orth(f-B, psi, Omega, False) u = u + next_term # Make only plot for i even if i % 2 == 0: comparison_plot(f, u, Omega, 'tmp_sin%02dx' % i, legend_loc='upper left', show=False, plot_title='s=%g, i=%d' % (s, i))