<jupyter_start><jupyter_text>ILI285 - Computación Científica I  / INF285 - Computación Científica      Newton's Method in $\mathbb{R}^n$       [S]cientific [C]omputing [T]eam       Version: 1.01  Table of Contents* [Newton's method](newton)* [Python Modules and Functions](py)* [Acknowledgements](acknowledgements)<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from ipywidgets import interact<jupyter_output><empty_output><jupyter_text>Newton's method<jupyter_code>f1= lambda x,y: x**2+y**2-1 
f2= lambda x,y: y-x**2
J = lambda x,y: np.array([[2*x, 2*y],[-2*x, 1]])
Newton = lambda x,y: np.array([[x],[y]])-np.linalg.solve(J(x,y),np.array([[f1(x,y)],[f2(x,y)]]))
delta = 0.025
x = np.arange(-1.5, 1.5, delta)
y = np.arange(-1.5, 1.5, delta)
X, Y = np.meshgrid(x, y)
Z1 = f1(X,Y)
Z2 = f2(X,Y)
plt.figure()
CS1 = plt.contour(X, Y, Z1,levels=[0])
CS2 = plt.contour(X, Y, Z2,levels=[0])
#plt.clabel(CS1, inline=1, fontsize=10)
#plt.clabel(CS2, inline=1, fontsize=10)
plt.grid()
plt.axis('equal')
plt.title(r'Newton $\mathbb{R}^n$')
plt.show()
def Show_Newton(x0=1.2,y0=0.3,n=0):
    plt.figure()
    CS1 = plt.contour(X, Y, Z1,levels=[0])
    CS2 = plt.contour(X, Y, Z2,levels=[0])
    plt.grid()
    plt.axis('equal')
    plt.title(r'Newton $\mathbb{R}^n$')
    plt.plot(x0,y0,'rx')
    print(x0,y0)
    for i in np.arange(n):
        xout=Newton(x0,y0)
        x1=float(xout[0])
        y1=float(xout[1])
        plt.plot(x1,y1,'rx')
        plt.plot([x0, x1],[y0, y1],'r')
        x0=x1
        y0=y1
        print(x0,y0)
    plt.show()
interact(Show_Newton,x0=(-1.4,1.4,0.1),y0=(-1.4,1.4,0.1), n=(0,100,1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21398684997011358, 'fraction_numerical': 0.06276150627615062, 'mean_word_length': 4.150769230769231, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '241791', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 830, 'n_tokens_neox': 781, 'n_words': 129, 'path': 'SC1/Bonus_Newton_Rn.ipynb', 'repo_name': 'xavierutox/Scientific-Computing', 'size': '1673'}