Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import numpy as np
- def phi(x):
- return math.exp(x)
- def f(x):
- return ((x+2)*math.exp(x) + math.exp(2*x+4) - 1)/(x+2)
- def K(x, y):
- return math.exp(x*y)
- start = 0
- end = 2
- n = 10
- h = (end - start)/n
- xi = [start + h*(i + 1/2) for i in range(n)]
- buffer = []
- real_sol = np.matrix([[np.float64(phi(xi[i])) for i in range(n)]]).transpose()
- _ = real_sol
- coeffs = np.matrix([[np.float64(f(xi[i-1])) for i in range(1, n+1)]]).transpose()
- for i in range(1, n+1):
- app = []
- for j in range(1, n+1):
- if i == j:
- app.append(np.float64(1 - h*K(xi[i-1], xi[j-1])))
- else:
- app.append(np.float64(-h*K(xi[i-1], xi[j-1])))
- buffer.append(app)
- System = np.matrix(buffer)
- solution = np.linalg.solve(System, coeffs)
- print("------------PHI(X)--------")
- print(real_sol)
- print("------------~PHI(X)--------")
- print(solution)
- print("--------------------")
- print(max([math.fabs(solution[i][0] - real_sol[i][0]) for i in range(n)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement