```python
import sympy
```

# Item V

Implement in Jupyter Notebook the Lagrange Interpolation method with *sympy*.
Then, find the interpolation polynomial for the following points:
* $(0,1),(1,2),(2,4)$. Is a second degree polynomial? If not, why is this?
* $(0,1),(1,2),(2,3)$. Is a second degree polynomial? If not, why is this?
---


```python
def lagrange(xs,ys):
    assert(len(xs)==len(ys))
    n = len(xs)
    x = sympy.Symbol('x')
    
    poly = 0
    for j in range(0,n):
        lag = ys[j]
        for m in range(0,n):
            if j!=m:
                lag *= (x-xs[m])/(xs[j]-xs[m])
        poly += lag
    return sympy.simplify(poly)
```


```python
lagrange([0,1,2],[1,2,4])
```




$\displaystyle \frac{x^{2}}{2} + \frac{x}{2} + 1$




```python
lagrange([0,1,2],[1,2,3])
```




$\displaystyle x + 1$



* The first points have to be interpolated by a second degree polynomial as they are not collinear, so they cannot be interpolated by a line.
* The second set of points are collinear, so they are interpolated by a polynomial of degree 1.

f0cb258e9bfd8d4b4f1e01c772846f6e08e608e2
ipynb
Jupyter Notebook
t1_questions/item_05.ipynb
autopawn/cc5-works
63775574c82da85ed0e750a4d6978a071096f6e7
MIT
t1_questions/item_05.ipynb
autopawn/cc5-works
63775574c82da85ed0e750a4d6978a071096f6e7
MIT
t1_questions/item_05.ipynb
autopawn/cc5-works
63775574c82da85ed0e750a4d6978a071096f6e7
MIT
Qwen/Qwen-72B
1. YES
2. YES