Algoritmlarni loyihash
Download 10.71 Kb.
|
Algaretimdan 5-amaliy ishi
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI QARSHI FILIALI TT VA KT FAKULTETI RI-11-21-GURUH TALABASINING “ ALGORITMLARNI LOYIHASH” FANIDAN TAYYORLAGAN 5-AMALIY ISHI Bajardi: G’oyimov Abbos . Qabul qildi: Ablaqulov K. QARSHI-2023 5-amaliy ish Mavzu: NP-To‘liq masalalar. NP-To‘liq masalalarga keltirish usullari 7 1) 3x-cosx-1=0 2) x3+0.2x2+0.5x-1.2=0 import math def equation1_f(x): return 3*x - math.cos(x) - 1 def equation1_df(x): return 3 + math.sin(x) def equation2_f(x): return x3 + 0.2*x2 + 0.5*x - 1.2 def equation2_df(x): return 3*x**2 + 0.4*x + 0.5 def iterate(f, df, x0, epsilon): x = x0 n = 0 while True: x_new = x - f(x) / df(x) n += 1 if abs(x_new - x) < epsilon: return x_new, n x = x_new def main(): # Birinchi funksiya uchun x0 = 1 epsilon = 0.0001 x, n = iterate(equation1_f, equation1_df, x0, epsilon) print(f"Funksiya 1: x = {x:.4f}, n = {n}") x0 = 0 epsilon = 0.0001 x, n = iterate(equation2_f, equation2_df, x0, epsilon) print(f"Funksiya 2: x = {x:.4f}, n = {n}") if name == "main": main() Download 10.71 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling