def fredholm_lhs(d, x_c, x_s, x_q, w_q, f): N_c, N_s = x_c.shape[0], x_s.shape[0] w_s = get_lagrange_poly_weights(x_s, array([1 for i in range(N_s)])) A = empty((N_c, N_s)) for i in range(N_c): for j in range(N_s): A[i][j] = num_quadrature(x_q, w_q, get_kernel(f, x_c[i], x_s, w_s, j, d)) return A
def get_biggest_difference(x_s, rho_hat, x_list): w_s = get_lagrange_poly_weights(x_s, rho_hat) ylist = zeros(len(x_list)) for i in range(len(x_list)): for j in range(len(x_s)): ylist[i] += w_s[j] * evaluate_lagrange(x_s, x_list[i], j) return ylist
return sum_q def rho(x): w, y = 3 * pi, -2 return sin(w * x) * exp(y * x) if __name__ == "__main__": d = 0.025 n_c = 40 n_s = 40 x_c = shift_chebyshev(0, 1, chebyshev_n(n_c)) x_s = shift_chebyshev(0, 1, chebyshev_n(n_s)) w_s = get_lagrange_poly_weights(x_s, array([1 for i in range(n_s)])) rho_hat = array([rho(x_s[i]) for i in range(n_s)]) F_analytic = load(open(rel_path + "/Data_files/F.pkl", "rb")) f_eval = F_analytic(x_c, d) fig, ax = init_plot('Oppgave 3') ax = set_axis_specs(ax, '$N_q$', 'Max Error', 24, 24) panel_list = arange(20, 301, 1) y_list_midpoint = empty(len(panel_list)) y_list_simpson = empty(len(panel_list)) y_list_LG = empty(len(panel_list)) for i in range(len(panel_list)): x_q, w_q = midpoint(0, 1, panel_list[i]) A = fredholm_lhs(d, x_c, x_s, w_s, x_q, w_q, f) F = dot(A, rho_hat)