```python
import sympy as sp
import pandas as pd
```


```python
x = sp.symbols('x')
f = sp.exp(x)
```


```python
nodes = [-0.3, -0.2, -0.1, 0, 0.1, 0.3]
values = [f.evalf(subs={x: n}) for n in nodes]
```


```python
new_value = 0.8
true_node = sp.log(0.8)
```


```python
def construct_lagrange_polynom(nodes, values, x):
    polynom = 0
    for i in range(len(nodes)):
        term = 1
        for j in range(len(nodes)):
            if i == j:
                continue
            term *= x - nodes[j]
            term /= nodes[i] - nodes[j]
        polynom += term * values[i]
    return polynom
```


```python
polynom = construct_lagrange_polynom(nodes, values, x)
```


```python
solutions = sp.solve(polynom - new_value)
```


```python
pd.DataFrame([[true_node], [solutions[0]], [true_node - solutions[0]]],
             index=['Exact value', 'Estimated', 'Error'], columns=[''])
```




<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></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>Exact value</th>
      <td>-0.223143551314210</td>
    </tr>
    <tr>
      <th>Estimated</th>
      <td>-0.223143564849920</td>
    </tr>
    <tr>
      <th>Error</th>
      <td>1.35357104968925e-8</td>
    </tr>
  </tbody>
</table>
</div>



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