|
Rasm 42. Ko’p shartli va ko’p takrolanuvchi jarayonli algoritmning blok Sxemasi. Gauss usulida tenglamalar sistemasini yechish uchun blok Sxema
|
bet | 90/135 | Sana | 22.05.2024 | Hajmi | 15,08 Mb. | | #250347 |
Bog'liq Fizik jarayonlarni kompyuterda modellashtirishRasm 42. Ko’p shartli va ko’p takrolanuvchi jarayonli algoritmning blok Sxemasi. Gauss usulida tenglamalar sistemasini yechish uchun blok Sxema.
Yuqoridagi blok sxema dasturni ishga tushirish uchun zarur buyruqlar tartibidir. Lekin quyidagi programmada esa buyruqlar blok sexmadagidan ko’p. chunki ko’p buyruqlar porgramma naijasini ko’rishdagi dizayn, natijani chiqarishda qulaylik yaratish uchun yozilgan.
]
Rasm 12. Tenglamalar sistemasini Gauss usulida yechish.
2-misol Y=ax2+bx+c kvadrat tenglamasining korenlar sonini toppish va kelip shiqish sabablarini aniqlovshi dastur tuzish. Bunda biz C++ dasturlash tilining tarmoqlanuvshi algoritmidan foydalanamiz.
Dastur kodi:
1 #include
2 #include
3 using namespace std;
4 int main()
5 { float a,b,c,x,x1,x2,D;
6 cout<<”a=”;cin >>a;
7 cout<<”b=”;cin >>b;
8 cout<<”c=”;cin >>c;
9 D=b*b-4*a*c;
10 If (D>0)
11 {x1=(-b-sqrt(D))/2*a;
12 X==(-b+sqrt(D))/2*a;
13 cout<<”x1=”<14 cout<<”x2=”<15 }
16 If (D==0)
17 { x=-b/2*a;
18 cout<<”x=”<19 If (D<0)
20 {cout<<”yechimga ega emas”<21 return 0;
22 }
Kvadrat tenglamaning yechimini Python dasturlash tilida amalga oshiramiz:
import math
print("Tenglama uchun koeffitsientlarni kiriting")
print("ax^2 + bx + c = 0:")
a = float(input("a = "))
b = float(input("b = "))
c = float(input("c = "))
discr = b ** 2 - 4 * a * c
print("Diskriminant D = %.2f" % discr)
if discr > 0:
x1 = (-b + math.sqrt(discr)) / (2 * a)
x2 = (-b - math.sqrt(discr)) / (2 * a)
print("x1 = %.2f \nx2 = %.2f" % (x1, x2))
elif discr == 0:
x = -b / (2 * a)
|
|
Bosh sahifa
Aloqalar
Bosh sahifa
Rasm 42. Ko’p shartli va ko’p takrolanuvchi jarayonli algoritmning blok Sxemasi. Gauss usulida tenglamalar sistemasini yechish uchun blok Sxema
|