Untitled

Apr 5th, 2021
487
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def solve_system(first, second, x_n, y_n):
2.     eps = 0.001
3.     max_iters = 100
4.
5.     f1 = partial(value_at_multidim, first)
6.     f2 = partial(value_at_multidim, second)
7.     Dxf1 = partial(value_at_multidim, partial_derivatives_n_dim(first)['x'])
8.     Dyf1 = partial(value_at_multidim, partial_derivatives_n_dim(first)['y'])
9.     Dxf2 = partial(value_at_multidim, partial_derivatives_n_dim(second)['x'])
10.     Dyf2 = partial(value_at_multidim, partial_derivatives_n_dim(second)['y'])
11.
12.     iteration = 0
13.
14.     f1xn = f1(x_n, y_n)
15.     f2xn = f2(x_n, y_n)
16.
17.     while abs(f1xn + f2xn) > eps:
18.         iteration += 1
19.
20.         Dxf1xn = Dxf1(x_n, y_n)
21.         Dyf1xn = Dyf1(x_n, y_n)
22.         Dxf2xn = Dxf2(x_n, y_n)
23.         Dyf2xn = Dyf2(x_n, y_n)
24.
25.         if iteration > max_iters:
26.             return None
27.
28.         x_n = x_n + (-f1xn * Dyf2xn + f2xn * Dyf1xn) / (Dxf1xn * Dyf2xn - Dyf1xn * Dxf2xn)
29.         y_n = y_n + (f1xn * Dxf2xn - f2xn * Dxf1xn) / (Dxf1xn * Dyf2xn - Dyf1xn * Dxf2xn)
30.
31.         f1xn = f1(x_n, y_n)
32.         f2xn = f2(x_n, y_n)
33.     return round(x_n, 4), round(y_n, 4)
RAW Paste Data