19.
|
Yechim joylashgan [a; b] oraliqni aniqlang vaoraliqni ikkiga bo’lish, vatarlar va urinmalar usuli bilan toping. E=0.001.
|
a) x3-2x-5=0
b) 2x-2x=0
|
1 usul
def f(x):
return x ** 3 - 2 * x - 5
a=float(input('a='))
b=float(input('b='))
eps=float(input('e='))
while True:
c=(a+b)/2
if f(a)*f(c)<0:
b=c
else:
a=c
if (b-a)<=eps:
break
print('Yechim=',c)
2 usul
def f(x):
return x ** 3 - 2 * x -5
def f1(x):
return 3 * x ** 2 - 6 * x + 7
def f2(x):
return 6 * x - 6
a = float(input('a = '))
b = float(input('b = '))
eps = float(input('eps = '))
while True:
if f(a) * f(b) > 0:
a = b
b = b - f(b) / f1(b)
if abs(b - a) < eps:
break
elif f(a) * f(b) < 0:
b = a
a = a - f(a) / f1(a)
if abs(b - a) < eps:
break
print('x = ', b
Do'stlaringiz bilan baham: |