Пример #1
0
def rho_numerical(d, lamb):
    A = fredholm_lhs(xc, xs, xq, w / 2, d)
    A_t = np.transpose(A)
    left_side = np.add(np.matmul(A_t, A), np.multiply(lamb, np.eye(Nc)))
    right_side = np.dot(A_t, b_pert(d))
    rho_numerical = np.linalg.solve(left_side, right_side)
    return rho_numerical
Пример #2
0
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)
        t = 0.5*(xq + 1)*(b - a) + a
        A_rho = np.matmul(fredholm_lhs(xc,xs,t,w/2),rho(omega,gamma,xs,N_eval))
        ny_liste = np.zeros(N_eval)
        for j in range(N_eval):
            ny_liste[j] = F[j] - A_rho[j]
        error[i-1] = np.linalg.norm(ny_liste,np.inf)
    return error
Пример #3
0
def error(d, lambda_list):
    A = fredholm_lhs(xc, xs, xq, w / 2)
    A_t = np.transpose(A)
    errorlist = np.zeros(len(lambda_list))
    for i in range(len(lambda_list)):
        left_side = np.add(np.matmul(A_t, A), np.multiply(lambda_list[i], np.eye(Nc)))
        right_side = np.dot(A_t, b_pert(d))
        rho_numerical = np.linalg.solve(left_side, right_side)
        single_error_list = np.zeros(Nc)
        for j in range(len(rho_numerical)):
            single_error_list[j] = abs(rho_numerical[j] - rho_analytical[j])
        errorlist[i] = np.linalg.norm(single_error_list, np.inf)
    return errorlist
Пример #4
0
def error(Nq_liste, a, b):
    # error = np.zeros(Nq)
    error = np.zeros(len(Nq_liste))
    F = fredholm_rhs(xc, F_eval)
    for i in range(len(Nq_liste)):
        xq, w = Newton_Cotes(a, b, Nq_liste[i])
        A_rho = np.matmul(fredholm_lhs(xc, xs, xq, w),
                          rho(omega, gamma, xs, N_eval))
        ny_liste = np.zeros(N_eval)
        for j in range(N_eval):
            ny_liste[j] = F[j] - A_rho[j]
        error[i] = np.linalg.norm(ny_liste, np.inf)
    return error
Пример #5
0
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
Пример #6
0
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)
        t = 0.5*(xq + 1)*(b - a) + a
        A_rho = np.matmul(fredholm_lhs(xc,xs,t,w/2),rho(omega,gamma,xs,N_eval))
        ny_liste = np.zeros(N_eval)
        for j in range(N_eval):
            ny_liste[j] = F[j] - A_rho[j]
        error[i-1] = np.linalg.norm(ny_liste,np.inf)
    return error
Пример #7
0
    F_error = np.zeros(len(xc))

    for i in range(len(xc)):
        F_error[i] = F_eval[i] * (1 +
                                  np.random.uniform(-delta, delta, N_eval)[i])
    return F_eval, F_error


F_eval1, F_error1 = finn_b(0.025)
F_eval2, F_error2 = finn_b(0.25)
F_eval3, F_error3 = finn_b(2.5)

analytisk_rho = rho(omega, gamma, xs, N_eval)
xq_old, w = np.polynomial.legendre.leggauss(N_eval**2)
xq = 0.5 * (xq_old + 1) * (b - a) + a
A = fredholm_lhs(xc, xs, xq, w / 2)
B = fredholm_rhs(xc, F_eval1)
losning = np.linalg.solve(A, B)

# analytisk rho uten perturbering
rho1 = np.linalg.solve(A, F_eval1)
rho2 = np.linalg.solve(A, F_eval2)
rho3 = np.linalg.solve(A, F_eval3)

# analytisk rho med perturbering
rho1_error = np.linalg.solve(A, F_error1)
rho2_error = np.linalg.solve(A, F_error2)
rho3_error = np.linalg.solve(A, F_error3)

plt.figure('F og F med feil')
plt.plot(xc, F_eval1, label='F ved d = 0.025')
Пример #8
0
start_t = time.time()
F = pickle.load(open("F.pkl", "rb"))
end_t = time.time()
print("Initialization took %f s." % (end_t - start_t))
F_eval = F(xc, d)

Nq = np.arange(20, 50, 1)

start_t = time.time()
error_list_lg = error_lg(Nq, a, b)
error_list = error(Nq, a, b)
end_t = time.time()
print('It took %f sec to find the error' % (end_t - start_t))

xq, w = Newton_Cotes(a, b, 40)
A_ganger_rho = np.matmul(fredholm_lhs(xc, xs, xq, w),
                         rho(omega, gamma, xs, N_eval))
b = fredholm_rhs(xc, F_eval)
print(r'A * $\rho$')
print(b)

# plotter F og A*rho
plt.figure()
plt.plot(xc, F_eval)
plt.plot(xc, A_ganger_rho)
plt.title('F(x)')
plt.xlabel('x')
plt.show()

plt.figure()
plt.plot(xc, A_ganger_rho)