Нужна помощь! Мне нужно отобразить график.Но я не знаю ка кэто правильно сделать с учетом множества функции.
Начальное приближение определять графически. Вывести количество
итераций
Начальное приближение определять графически. Вывести количество
итераций
Python:
def function_exercise(xy):
x, y = xy
return [np.tan(x * y) - x * x,
0.7 * x * x + 2 * y * y - 1]
def jacobian_exercise(xy):
x, y = xy
return [[(y / (np.cos(x * y) ** 2)) - 2 * x, (x / (np.cos(x * y) ** 2))],
[1.4 * x, 4 * y]]
def iter_newton(X, function, jacobian, imax=1e6, tol=1e-5):
for i in range(int(imax)):
J = jacobian(X) # calculate jacobian J = df(X)/dY(X)
Y = function(X) # calculate function Y = f(X)
dX = np.linalg.solve(J, Y) # solve for increment from JdX = Y
X -= dX # step X by dX
i += 1
print(f'Number of iterations: {i=}\t Result: {X=}')
if np.linalg.norm(dX) < tol: # break if converged
print('Converged')
break
return X
def Newton_sys_graphic():
fig1, ax = plt.subplots(figsize=(8, 6))
plt.ylabel(r'$y$', fontsize=13, fontname='Arial', color='white')
plt.xlabel(r'$x$', fontsize=13, fontname='Arial', color='white')
plt.grid(which='both', linewidth=1.5, linestyle='-', color='gray')
ax.tick_params(which='major', length=8, width=2)
ax.tick_params(which='minor', length=8, width=2)
ax.minorticks_on()
ax.grid(which='major',
linewidth=2)
ax.grid(which='minor',
linestyle=':')
plt.scatter(*function_exercise(11), color="blue", marker="s", edgecolors='yellow', linewidth=3, s=60, hatch='+o')
# plt.plot(*function_exercise(1, 1))
legend = plt.legend(['Initial approximation'], loc='upper right', shadow=True, fontsize='x-large',
frameon=True, title="Легенда", title_fontsize=15, framealpha=1)
frame = legend.get_frame()
frame.set_facecolor('black')
frame.set_edgecolor('red')
plt.title("Initial approximation")
mplcyberpunk.add_gradient_fill(alpha_gradientglow=0.5)
mplcyberpunk.add_glow_effects()
plt.show()
fig1.savefig('newton_point.png', dpi=300, bbox_inches='tight')
X_0 = np.array([1, 1], dtype=float)
print(iter_newton(X_0, function_exercise, jacobian_exercise))
Newton_sys_graphic()