def rho_error(Ns, Nc, F, d): error = np.zeros(len(Ns)) for i in range(len(Ns)): xs = chebyshev(a, b, Ns[i]) xc = chebyshev(a, b, Nc[i]) xq_old, w = np.polynomial.legendre.leggauss(Ns[i]**2) xq = 0.5 * (xq_old + 1) * (b - a) + a A = fredholm_lhs(xc, xs, xq, w / 2) F_eval = F(xc, d) B = fredholm_rhs(xc, F_eval) losning = np.linalg.solve(A, B) ny_liste = np.zeros(Ns[i]) for j in range(Ns[i]): ny_liste[j] = rho(omega, gamma, xs, Ns[i])[j] - losning[j] error[i] = np.linalg.norm(ny_liste, np.inf) return error
a = 0 b = 1 # d is the distance from the measurements in the kernel d = 2.5E-02 # we use rho(y) = exp(gamma*y)*sin(omega*y) as an example gamma = -2 omega = 3*np.pi # maximal order of the Taylor series expansion Nmax = 75 # evaluate the integral expression at x_eval N_eval = 40 Nq = 40 xq,w = np.polynomial.legendre.leggauss(Nq) t = 0.5*(xq + 1)*(b - a) + a xc = chebyshev(a,b,N_eval) xs = chebyshev(a,b,N_eval) F = analytical_solution(a,b,omega,gamma,Nmax) F = pickle.load( open( "F.pkl", "rb" ) ) F_eval = F(xc,d) A_ganger_rho = np.matmul(fredholm_lhs(xc,xs,t,w/2),rho(omega,gamma,xs,N_eval)) def error_lg(Nq_liste,a,b): #error = np.zeros(Nq) error = np.zeros(len(Nq)) F = fredholm_rhs(xc,F_eval) for i in Nq_liste: xq,w = np.polynomial.legendre.leggauss(i)
import numpy as np from Vitber.Prosjekt1.F_analytisk import analytical_solution from Vitber.Prosjekt1.metoder import chebyshev, fredholm_lhs, rho F = pickle.load(open("F.pkl", "rb")) Nc = Ns = 30 a = 0 b = 1 gamma = -2 omega = 3 * np.pi delta = 10 ** (-3) d1 = 0.25 d2 = 2.5 xs = chebyshev(a, b, Ns) xc = chebyshev(a, b, Nc) F_eval = F(xc, d1) xq_old, w = np.polynomial.legendre.leggauss(Nc ** 2) xq = 0.5 * (xq_old + 1) * (b - a) + a def b_pert(d): F_eval = F(xc, d) F_error = np.zeros(Nc) for i in range(Nc): F_error[i] = F_eval[i] * (1 + np.random.uniform(-delta, delta, Nc)[i]) return F_error