```python
import numpy as np
from sympy import *
```


```python
def newton_integration(function, a, b, m):
    h = (b - a)/(3*m)
    x_values = np.arange(a, b, h)
    sum = function(a) + function(x_values[-1]*3)
    subsum1 = 0
    subsum2 = 0
    for i in range(m):
        subsum1 += function(x_values[3*i-2]) + function(x_values[3*i-1])
        if i != m - 1:
            subsum2 += function(x_values[3*i])
    sum += 3*subsum1
    sum += 2*subsum2
    return 3*h/8*sum
```


```python
x = Symbol('x')
function = lambdify(x, sin(x), 'numpy')
a = 0
b = np.pi
m = 1000
```


```python
from scipy import integrate
exact_integral = -cos(np.pi) + cos(0)
newton_integral = newton_integration(function, a, b, m)
print('Вычисленный интеграл: ', newton_integral)
print('Точное значение:', exact_integral)
print('Ошибка:', exact_integral-newton_integral)
```

    Вычисленный интеграл:  1.999995065203693
    Точное значение: 2.00000000000000
    Ошибка: 4.93479630692129e-6


a7eb22d7ef2efcbca37998dab4b02fd7778a4414
ipynb
Jupyter Notebook
Numerical-Methods/Newton-Integration/newton integration.ipynb
cmlimm/uni-projects
b63ac71cc0b971c7f035096a6bd15b0cbb5bb9f6
MIT
Numerical-Methods/Newton-Integration/newton integration.ipynb
cmlimm/uni-projects
b63ac71cc0b971c7f035096a6bd15b0cbb5bb9f6
MIT
Numerical-Methods/Newton-Integration/newton integration.ipynb
cmlimm/uni-projects
b63ac71cc0b971c7f035096a6bd15b0cbb5bb9f6
MIT
2020-10-29T18:31:32.000Z
2020-10-29T18:31:32.000Z
Qwen/Qwen-72B
1. YES
2. YES