```python
from sympy import Symbol, init_printing, Rational
from math import pi
```


```python
x = Symbol("x")
```


```python

def lagrangePol(n, xs, ys):
    p = 0
    for k in range(0, n+1):
        p += ys[k] * lagrangeL(n, xs, k)
    return p    


```


```python
def lagrangeL(n, xs, k):
    L = 1
    for i in range(0, n+1):
        if (i != k):
            L *=(x - xs[i] )/(xs[k] - xs[i])
    return L

```


```python
xs = [1,3,5,7]
```


```python
ys = [1.45,2.75,4.65,6.87]
```


```python
pol = lagrangePol(3, xs, ys)
```


```python
pol.expand()
```




$\displaystyle - 0.00583333333333336 x^{3} + 0.1275 x^{2} + 0.215833333333333 x + 1.1125$




```python
pol.subs(x,3)
```




$\displaystyle 2.75$




```python

```

2fc6c54e6290c33ffa0c08ee9264a87bc0d57d7f
ipynb
Jupyter Notebook
lagrangeJupiter.ipynb
HeyChobe/numerical-analysis
cb0fc1719f52564eac6b4896a0afb30b16ac87d7
MIT
2021-07-19T23:49:27.000Z
2021-07-19T23:49:27.000Z
lagrangeJupiter.ipynb
HeyChobe/numerical-analysis
cb0fc1719f52564eac6b4896a0afb30b16ac87d7
MIT
lagrangeJupiter.ipynb
HeyChobe/numerical-analysis
cb0fc1719f52564eac6b4896a0afb30b16ac87d7
MIT
2021-07-20T03:17:54.000Z
2021-07-20T03:17:54.000Z
Qwen/Qwen-72B
1. YES
2. YES