-
Notifications
You must be signed in to change notification settings - Fork 5
/
Сombined method.py
44 lines (38 loc) · 959 Bytes
/
Сombined method.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import matplotlib.pyplot as plt
import numpy as np
def f(x):
return np.sin(x)
def p(x):
return np.cos(x)
a = -10
b = 10
h = 1
points = []
eps = 0.001
n = 0
b1 = a
a1 = a
for i in range(int((b - a)//h)):
b1 += h
a1 = b1 - h
if b1 != 0:
if f(a1) * f(b1) <= 0:
xstart = a1
xend = b1
while abs(abs(xstart)-abs(xend)) >= eps:
xp = xend - f(xend)*(xstart-xend)/(f(xstart)-f(xend))
xend -= f(xend)/p(xend)
xstart,xend = xp,xstart
n += 1
points.append(xp)
print(n,'=',xp)
plt.figure('Добрый день')
points = np.array(points)
x1 = np.linspace(a,b,1000)
plt.plot(x1,f(x1),color='g', linewidth=1.0)
plt.plot(points,f(points),'ro')
plt.subplot(111).spines['bottom'].set_position('zero')
plt.title('$Kulish$')
plt.ylabel('$y=sin(x)$')
plt.grid(True)
plt.show()