Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from Progonka import *
- def main():
- begin = 0
- end = 2
- h = 0.01
- y_0 = 0
- y_T = 0
- x = []
- for i in np.arange(begin, end+h, h):
- x.append(h*i)
- n = len(x)
- matrix = np.zeros((n, n))
- x, y = Razn_method(x, matrix, n, h, y_0, y_T)
- y_ans = [Y(i) for i in x]
- plt.plot(x, y)
- plt.plot(x, y_ans)
- plt.suptitle("График решения краевой задачи")
- plt.grid()
- for i in range(n+1):
- print("{0} - {1}".format(y[i],y_ans[i]))
- def Razn_method(x, matrix, n, h, y_0, y_T):
- for i in range(1, n):
- if i > 0: matrix[i][i-1] = (2*p(x[i])*h)/(2*h**2)
- matrix[i][i] = (q(x[i])*h**2-2)/(h**2)
- if i < n-2: matrix[i][i+1] = (2-p(x[i])*h)/(2*h**2)
- d = [f(i) for i in x]
- y = Tridiagonal_solve(matrix, d, n-1)
- y_alt = np.linalg.solve(matrix, d)
- print(y)
- print(y_alt)
- y.insert(y_0, 0)
- y.append(y_T)
- return x, y
- def Y(x): return x*x*(x-2)
- def p(x): return -x*x
- def q(x): return -x**3
- def f(x):
- return -x**6 - 2*x**5 + 3*x**4 - 4*x**3+6*x-4
- if __name__ == "__main__" :
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement