Blok sxemasi esa pastdagi rasm bilan ta'minlanadi

|
Blok sxemasi esa pastdagi rasm bilan ta'minlanadi
|
bet | 3/3 | Sana | 22.05.2024 | Hajmi | 0,77 Mb. | | #250665 |
Bog'liq Xamrayeva G.algoritm 2-amaliyBlok sxemasi esa pastdagi rasm bilan ta'minlanadi:
boshlash
П=3,1415
1.8x2-sin10x
a=0; b=10;
c=(a+b)/2
F(c)=0,0
(f(c)·f(a) < 0
a=c;
b=c;
ILDIZ
TUGASH
C++da tuzilgan dasturi ;
#include
#include
using namespace std ;
const double PI = 3.14159265;
const double epsilon = 0.0001;
double f(double x) {
return 1.8 * pow(x, 2) - sin(10 * x);
}
int main() {
double a = 0, b = 10;
double c;
while ((b - a) >= epsilon) {
c = (a + b) / 2;
if (f(c) == 0.0) {
break;
} else if (f(c) * f(a) < 0) {
b = c;
} else {
a = c;
}
}
cout << "Ildiz: " << c << endl;
return 0;
}
2. Aniqlangan oraliqda ildizning taqribiy qiymatini 0.01 aniqlikda iteratsiya usuli bilan hisoblang.
#include
#include
using namespace std;
const double epsilon = 0.01;
double f(double x) {
return 1.8 * pow(x, 2) - sin(10 * x);
}
int main() {
double x0 = 0;
double x1 = x0 + epsilon;
while (abs(x1 - x0) >= epsilon) {
x0 = x1;
x1 = x0 - f(x0) / (3.6 * x0 - 10 * cos(10 * x0));
if (abs(f(x1)) < epsilon) {
break;
}
}
cout << "Ildizning taqribiy qiymati: " << x1 << endl;
return 0;
}
3. Aniqlangan oraliqda ildizni ketma-ket yaqinlashish va ikkiga bo‘lish usuli bilan taqribiy hisoblang.
#include
#include
using namespace std;
double f(double x) {
return 1.8 * pow(x, 2) - sin(10 * x);
}
double findRoot(double a, double b, double epsilon) {
double x1 = a;
double x2 = b;
double x3;
do {
x3 = (x1 * f(x2) - x2 * f(x1)) / (f(x2) - f(x1));
if (f(x1) * f(x3) < 0) {
x2 = x3;
} else {
x1 = x3; }
} while (abs(f(x3)) > epsilon)
return x3; }
int main() {
double a = 0.0;
double b = 1.0;
double epsilon = 0.0001;
double root = findRoot(a, b, epsilon);
cout << "Nazoratli ildiz: " << root << endl;
return 0;}
1. Ildizlarning qisqa atrofini analitik yoki grafik usulda aniqlang.
2) x3+3x2+6x-1=0;
Berilganlar
|
Belgilashlar
|
matn bo‘yicha
|
dastur bo‘yicha
|
Tenglama funksiyasi
|
f(x)= x3+3x2+6x-1
|
f(x)=pow(x,3)+3*pow(x,2)+6*x-1
|
Diskriminant
|
D=b2 - 4ac
|
discriminant = b * b - 4 * a * c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dastur algoritmi quyidagicha bo'ladi:
1. Kiritilgan a, b, va c qiymatlari uchun ildizlarni topish uchun findRoots funksiyasini chaqir.
2. Funksiya discriminantni hisoblaydi: discriminant = b*b - 4*a*c.
3. Agar discriminant > 0 bo'lsa, ikkita ildiz topiladi:
- Birinchi ildiz: root1 = (-b + sqrt(discriminant)) / (2*a).
- Ikkinchi ildiz: root2 = (-b - sqrt(discriminant)) / (2*a).
- Natijani chiqarish: "ildizlar 2 ta: root1 va root2".
4. Agar discriminant == 0 bo'lsa, bitta ildiz topiladi:
- Ildiz: root = -b / (2*a).
- Natijani chiqarish: "ildizlar 1 ta: root".
5. Agar discriminant < 0 bo'lsa, ildizlar yo'q deyiladi.
- Natijani chiqarish: "ildizlar yo'q".
Blok sxema:
BOSHLASH
a=1; b=3; c=6;
D=b2 - 4ac
D<0
D=0
Yechim yo’q
root=-b/2a
root=-b+√D/2a root=-b-√D/2a
1ta ildiz yechim
2ta ildiz yechim
TUGASH
C++da tuzilgan dasturi ;
#include
#include
using namespace std;
void findRoots(double a, double b, double c) {
double discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
// ildizlar 2 ta
double root1 = (-b + sqrt(discriminant)) / (2 * a);
double root2 = (-b - sqrt(discriminant)) / (2 * a);
cout << "ildizlar 2 ta: " << root1 << " va " << root2 << endl;
} else if (discriminant == 0) {
// ildizlar 1 ta
double root = -b / (2 * a);
cout << "ildizlar 1 ta: " << root << endl;
} else {
// ildizlar yo'q
cout << "ildizlar yo'q" << endl;
}
}
int main() {
double a = 1;
double b = 3;
double c = 6;
findRoots(a, b, c);
return 0;}
0>
|
| |