```python
import sympy as sp
import pandas as pd
%matplotlib inline
```


```python
x, y = sp.symbols('x y')
f = sp.tan(y - 0.8 * x) + 0.8 * x * y - 0.3
g = x ** 2 + y ** 2 - 1.7
```


```python
plot = sp.plot_implicit(sp.Eq(f, 0), show=False, line_color='blue')
plot.extend(sp.plot_implicit(sp.Eq(g, 0), show=False, line_color='green'))
plot.show()
```


```python
def newton_system(x, y, f, g, x0, y0):
    dfdx = f.diff(x)
    dfdy = f.diff(y)
    dgdx = g.diff(x)
    dgdy = g.diff(y)
    
    d = dfdx * dgdy - dgdx * dfdy
    dx = f * dgdy - g * dfdy
    dy = dfdx * g - dgdx * f

    xs, ys, norms, fs, gs = [], [], [], [], []
    xk, yk = x0, y0
    while True:    
        new_x = xk - (dx / d).evalf(subs={x: xk, y: yk})
        new_y = yk - (dy / d).evalf(subs={x: xk, y: yk})
        xs.append(new_x)
        ys.append(new_y)

        norm = sp.sqrt((new_x - xk) ** 2 + (new_y - yk) ** 2)
        norms.append(norm)
        fs.append(f.evalf(subs={x: new_x, y: new_y}))
        gs.append(g.evalf(subs={x: new_x, y: new_y}))

        xk, yk = new_x, new_y

        if norm < 1e-5 and len(xs) > 1:
            break
    return pd.DataFrame(list(zip(xs, ys, norms, fs, gs)), columns=['x', 'y', 'norm', 'f', 'g'])
```


```python
newton_system(x, y, f, g, 1, 1)
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>x</th>
      <th>y</th>
      <th>norm</th>
      <th>f</th>
      <th>g</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1.22761708889715</td>
      <td>0.622382911102848</td>
      <td>0.440912922225209</td>
      <td>-0.0648343503263468</td>
      <td>0.194404204985173</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1.14149633521898</td>
      <td>0.636074171385597</td>
      <td>0.0872022638595296</td>
      <td>-0.00358082004103558</td>
      <td>0.00760423482222702</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.13755666993897</td>
      <td>0.637166805074043</td>
      <td>0.00408837509233626</td>
      <td>-8.94822418305518e-6</td>
      <td>1.67148108958352e-5</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.13754769473498</td>
      <td>0.637169712315441</td>
      <td>9.43431710133745e-6</td>
      <td>-5.15817799583199e-11</td>
      <td>8.90062924372405e-11</td>
    </tr>
  </tbody>
</table>
</div>




```python
newton_system(x, y, f, g, -1, -1)
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>x</th>
      <th>y</th>
      <th>norm</th>
      <th>f</th>
      <th>g</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>-0.822059767940987</td>
      <td>-1.02794023205901</td>
      <td>0.180120467334300</td>
      <td>-0.0121769613176794</td>
      <td>0.0324433827527268</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-0.824116762561558</td>
      <td>-1.01051444859597</td>
      <td>0.0175467705339115</td>
      <td>-0.000187332632752991</td>
      <td>0.000307889156169836</td>
    </tr>
    <tr>
      <th>2</th>
      <td>-0.824171430058251</td>
      <td>-1.01031752219007</td>
      <td>0.000204373541676120</td>
      <td>-3.26758676647519e-8</td>
      <td>4.17685447475136e-8</td>
    </tr>
    <tr>
      <th>3</th>
      <td>-0.824171440931074</td>
      <td>-1.01031749264951</td>
      <td>3.14779734395557e-8</td>
      <td>-7.59514473637850e-16</td>
      <td>8.46188933633038e-16</td>
    </tr>
  </tbody>
</table>
</div>



8ccd1e672f9a80863176a5ffa125e9eac0b37a78
ipynb
Jupyter Notebook
year-2/computational-workshop/task-7.ipynb
Sergobot/university
7cd8c07fc660f1e19127c6488991ddd59d99643c
MIT
2019-09-05T08:43:47.000Z
2019-09-05T08:43:52.000Z
year-2/computational-workshop/task-7.ipynb
Sergobot/university
7cd8c07fc660f1e19127c6488991ddd59d99643c
MIT
year-2/computational-workshop/task-7.ipynb
Sergobot/university
7cd8c07fc660f1e19127c6488991ddd59d99643c
MIT
2020-10-04T07:40:20.000Z
2021-09-18T07:12:08.000Z
Qwen/Qwen-72B
1. YES
2. YES