Taqribiy sonlar. Ularning absolyut va nisbiy xatosi. Qiymatga ega bo’lgan raqam. To’g’ri ishoralar soni doc
1-LABORATORIYA ISHI Mavzu: Taqribiy sonlar. Ularning absolyut va nisbiy xatosi. Qiymatga ega bo’lgan raqam. To’g’ri ishoralar soni . Differensiallanadigan funksiyaning y = f ( x 1 , x 2 … , x n ) absolyut xatosi argumentlarning x1,x2… ,xn deyarli kichik xato bilan chiqariladigan Δ x 1 , Δ x 2 , … Δ x n o’cham bilan baholanadi. ∆ y = ∑ i = 1n ❑ | ∂ f ∂ x i | ⋅ Δ x i (1) Bundan funksiyaning nisbiy xatosi δ y = Δ y y ∗ 100 % ( 2 ) kabi bo’ladi. Masalaning qo’yilishi: Quyidagi funksiyaning absolyut va nisbiy xatoligini aniqlang. y= a+b √(c− d)∗m a=16.342 ±0.0001 ;b= 2.5 ±0,003 ; c= 38.17 ±0,002 d=9.14 ±0,005 n=3.6 ±0,04 m= 9.14 ±0,04 Yechish: Demak: a=16.342 ;b= 2.5 ;c=38.17 ;d=9.14 ;n=3.6 ;m=9.14 ∆ a = 0.001 ; ∆ b = 0.003 ; ∆ c = 0.002 ∆ d = 0.002 ∆ n = 0.04 ∆ m = 0.005 (1) formulaga asosan funksiyaning absolyut xatosini topamiz. ∆ y = ∂ y ∂ a ⋅ Δ a + ∂ y ∂ b ⋅ Δ b + ∂ y ∂ c ⋅ Δ c + ∂ y ∂ d ⋅ Δ d + ∂ y ∂ m ⋅ m = ¿ 1 √( 38.17 − 9.14 ) ∗ 9.14 0.001 + 1 √( 38.17 − 9.14 ) ∗ 9.14 0.003 − 16.342 + 2.5 2 ∗ √ 9.14 ∗ ( 38.17 − 9.14 ) 3 2 ∙ 0.002
+ 16.342 + 2.5 2 ∗√ 9.14 ∗ ( 38.17 − 9.14 ) 3 2 ∙ 0.002 + 16.342 + 2.5 2 ∗ 9.14 3 2 ( 38.17 − 9.14 ) 1 2 ∙ 0.005 = 0.000003 Endi esa funksiyaning qiymatini hisoblaymiz. y= a+b √(c− d)∗m = 16.342 +2.5 √(38.17 − 9.14 )∗9.14 =16.28004 Bunda funksiyaning nisbiy xatosi (2) formulaga asosan: δ y = Δ y y ∙ 100 % = 0.00156142 1.15673 ∙ 100 % = 0.0000018 ≈ 0.1 % kabi bo’ladi. Dastur kodi: #include <iostream> #include <cmath> #include <iomanip> double del_x ( double a, double b, double c, double d, double m, double del_a, double del_b, double del_c, double del_d, double del_m) { return std :: abs ((b * del_a) / ( 2 * sqrt ((c - d) * m) * (a + b))) + std :: abs ((-a * del_b) / ( 2 * sqrt ((c - d) * m) * (a + b))) + std :: abs (((a + b) * del_c) / ( 2 * pow ((c - d) * m, 1.5 ))) + std :: abs (((a + b) * del_d) / ( 2 * sqrt ((c - d) * m))) + std :: abs (((a + b) * del_m) / ( 2 * sqrt ((c - d) * m) * m)); } double x ( double a, double b, double c, double d, double m) { return (a + b) / sqrt ((c - d) * m); } double nisbiy ( double del_x, double x) { return (del_x / x) * 100 ; } int main () {
double a = 16.342 ; double b = 2.5 ; double c = 38.17 ; double d = 9.14 ; double m = 9.14 ; double del_a = 0.001 ; double del_b = 0.003 ; double del_c = 0.002 ; double del_d = 0.002 ; double del_m = 0.005 ; double absolut_xato = del_x(a, b, c, d, m, del_a, del_b, del_c, del_d, del_m); double funksiya_qiymati = x(a, b, c, d, m); double nisbiy_xato = nisbiy(absolut_xato, funksiya_qiymati); std :: cout << "Funksiyaning qiymati: " << funksiya_qiymati << std :: endl ; std :: cout << "Absolut xatolik: " << absolut_xato << std :: endl ; std :: cout << "Nisbiy xatolik: " << std ::fixed << std ::setprecision( 1 ) << nisbiy_xato << " %" << std :: endl ; return 0 ; } Dastur natijasi: Chiziqlimas tenglamalarni yechishning sonli usullari. Nyuton, oddiy iteratsiya, vatarlar usullari. Nyuton usuli
def f(x): return x**2 - 4 def f_prime(x): h = 1e-6 return (f(x + h) - f(x)) / h def newton_method(f, f_prime, x0, tol=1e-6, max_iter=100): x = x0 for i in range(max_iter): fx = f(x) if abs(fx) < tol: break fp = f_prime(x) if fp == 0: break x = x - fx / fp return x x0 = 2.0 root = newton_method(f, f_prime, x0) print("Natija:", root) Vatarlar usuli # Sonli usul def sonli_usul(n): if n == 0: return 1 else: return n * sonli_usul(n-1) # Vatarlar usuli def vatarlar_usuli(n): result = 1 for i in range(1, n+1): result *= i return result n = int(input("Ixtiyoriy son kiriting: ")) print(f"{n} ning sonli usuli: {sonli_usul(n)}") print(f"{n} ning vatarlar usuli: {vatarlar_usuli(n)}") Oddiy iteratisiya usuli def iteratsiya_method(a, b, c): epsilon = 0.0001 x0 = 0 while True: x1 = (b * x0**2 + c) / a if abs(x1 - x0) < epsilon: break x0 = x1 print("Iteratsiya usuli natijasi:", x1)
a = float(input("a ni kiriting: ")) b = float(input("b ni kiriting: ")) c = float(input("c ni kiriting: ") iteratsiya_method(a, b, c) Oddiy itereatsiya usuli x 3 − 3 x 2 + 12 x − 12 = 0 f 1( x ) = x 3 − 3 x 2 f2(x)=12 x− 12 x -1 0 1 y -28 -12 -2 x0≤12 x n + 1 = x n − f ( x n ) f I ( x n ) f I ( x 0 ) = 3 x 2 − 6 x + 12 x1= x0− f(x0) fI(x0) ≈7,5 x2= x1− f(x1) fI(x1) ≈6,3 | x n − x n − 1 ≤ ε ε ≤ 10 − 4 | x ≈ 1,22 Vatar usuli f ( a) < 0 x n + 1 = x n − f ( x n ) f ( b ) − f ( x n ) ∗ ( b − x n ) f ( a) = − 12 f ( x 1 ) = − 12 − − 2316 − 4632 ∗ ( − 12 − 12 ) = − 1,99x -1 0 1 2 f1(x) -4 0 -2 -4 f 2 ( x ) -24 -12 0 12