Yechim joylashgan [a; b] oraliqni aniqlang vaoraliqni ikkiga bo’lish, vatarlar va urinmalar usuli bilan toping. E=


Download 14.4 Kb.
Sana31.01.2024
Hajmi14.4 Kb.
#1831466

19.

Yechim joylashgan [a; b] oraliqni aniqlang vaoraliqni ikkiga bo’lish, vatarlar va urinmalar usuli bilan toping. E=0.001.

a) x­­­­­­­3-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
Download 14.4 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling