Загрузил Muhammadamin Islomov

Algoritmlarni loyihalash 1-ish

реклама
O’ZBEKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALAR
VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
“Algoritmlarni loyihalash “
CAL004-1"
fanidan
1-AMALIY ISHI
Bajardi:
Islomov Muhammadamin
Qabul qildi:
Toshkent – 2024
Axmedov Oybek
Algebraik va transtsendent tenglamalar yechimlarini taqribiy usullar bilan
topish.
3-variant.
a) x3-x7=0
b) lnx+2 x =0
1-Vazifa. Tenglamalar yechimlari joylashgan [a; b] oraliqni grafik va analitik
usullar bilan ajrating.
2-Vazifa. Tenglamalar yechimlari joylashgan oraliqlar aniqlangandan so’ng
taqribiy yechimlarini oraliqni teng ikkiga bo’lish usulida E=0.001 aniqlikda
hisoblang. Algoritmini tuzib, dasturlash tilida dastur kodini yozib natija oling.
3-Vazifa. Algebraik va transtsendent tenglamalarning taqribiy yechimlarini
vatarlar va urinmalar usuli bilan toping. Algoritmini tuzib, dasturlash tilida dastur
kodini yozib natija oling
1- vazifani bajarish uchun ko’rsatma:
a) Analitik usul. Quyidagi dastur kodidan foydalanib tenglama argumenti X ga
qiymatlar bering, funktsiya Y ni hisoblang va jadvalni to’ldiring.
#include <iostream>
#include <cmath>
double f(double x) {
// Write the right side of the equation here
return pow(x, 3) - x - 7;
}
int main() {
double a, b, eps;
std::cout << "a,b,eps=?";
std::cin >> a >> b >> eps;
double c = (a + b) / 2;
while (std::abs(b - a) > eps) {
if (f(a) * f(c) < 0) {
b = c;
} else {
a = c;
}
c = (a + b) / 2;
}
std::cout << "Yechim = " << (a + b) / 2 << std::endl;
return 0;
}
a)
X
Y
-3
-31
-2
-13
-1
-7
0
-7
1
-7
2
-1
3
17
Natija:
Jadvalda Y qiymatlarining ishoralari o’zgarishiga qarab yechimlar joylashgan
[a; b] oraliqni aniqlang.
b) Grafik usul. Berilgan tenglamani ikki kismga, f1 va f2 ga ajrating, bunda
f1 = f2. Yukorida keltirilgan dastur kodi bilan hisoblab topilgan Y1=f1 va Y2=f2
funktsiyalar qiymatlarini jadvallarga kiriting.
Y1=f1= x3-x
X
-3
Y1
-24
X
-3
Y2
7
-2
-6
-2
7
Y1=f1= x3-x
Y2=f2=7
-1
-2
-1
7
0
0
0
7
Y2=f2=7
1
0
1
7
Y1=f1= lnx
2
6
2
7
3
24
3
7
Y2=f2=2√𝒙
2- vazifa;
Oraliqni teng ikkiga bo’lish usulining algoritmi:
F (x) =…
a,b
йук
F(a)(f(b)0
ха
Е
с=(a+b)/2
ха
йук
f(a)f(с)<0
b=c
a=c
йук
b-a<E
ха
Oraliqni teng ikkiga bo’lish usuli uchun dastur kodi:
#include <iostream>
#include <cmath>
double f(double x) {
// Write the right side of the equation here
}
int main() {
double a, b, eps;
std::cout << "a,b,eps=?";
std::cin >> a >> b >> eps;
double c = (a + b) / 2;
while (std::abs(b - a) > eps) {
if (f(a) * f(c) < 0) {
b = c;
} else {
a = c;
}
c = (a + b) / 2;
}
std::cout << "Yechim = " << (a + b) / 2 << std::endl
return 0;
}
Natija:
3 - vazifa
Urinmalar usulining algoritmi:
Boshlash
F(x)=…
F1(x)= …
а,в,е
ха
йўқ
f(a)f(с)<0
x0=a
x0=x
x0=b
йўқ
=
ха
Ix-x0I<e
x
тамом
Urinmalar usuli uchun dastur kodi:
#include <iostream>
#include <cmath>
// Function definition for F(x) = x^3 - x - 7
double F(double x) {
return pow(x, 3) - x - 7;
}
// Derivative of F(x), you need this for the secant method
double F1(double x) {
return 3 * pow(x, 2) - 1;
}
int main() {
double a, b, x1, x2, eps;
std::cout << "a, b = ";
std::cin >> a >> b;
std::cout << "Enter the desired accuracy: ";
std::cin >> eps;
if (F(a) * F1(a) > 0) {
x1 = b;
} else {
goto label2;
}
label1:
x2 = x1 - F(x1) / F1(x1);
if (std::abs(x2 - x1) > eps) {
x1 = x2;
goto label1;
} else {
goto label3;
}
label2:
if (F(a) * F1(a) < 0) {
x1 = a;
}
label4:
x2 = x1 - F(x1) / F1(x1);
if (std::abs(x2 - x1) > eps) {
x1 = x2;
goto label4;
}
label3:
std::cout << "Root of the equation = " << x1 << std::endl;
return 0;
}
Natija:
Vatarlar usuli uchun dastur kodi:
#include <iostream>
#include <cmath>
// Define the function f(x) = x^3 - x - 7
double F(double x) {
return pow(x, 3) - x - 7;
}
// Define the first auxiliary function F1(x)
double F1(double x) {
return pow(x, 3) - x - 7; // Same as the main function for this equation
}
// Define the second auxiliary function F2(x)
double F2(double x) {
return 7; // Constant function, as per the division requirement
}
int main() {
double a, b, x1, x2, eps;
std::cout << "Enter the initial guesses a and b: ";
std::cin >> a >> b;
std::cout << "Enter the desired accuracy (eps): ";
std::cin >> eps;
if (F1(a) * F2(a) > 0) {
x1 = a;
} else {
x1 = b;
}
while (true) {
x2 = x1 - F(x1) * (x1 - a) / (F(x1) - F(a));
if (std::abs(x2 - x1) < eps) {
break; // Stop iterating if the desired accuracy is achieved
}
x1 = x2;
}
std::cout << "Root of the equation = " << x2 << std::endl;
return 0;
}
Dastur kodida: F - tenglamani o’ng tomoni;
F1 - tenglama o’ng tomonidan olingan birinchi hosila
F2 - tenglama o’ng tomonidan olingan ikkinchi hosila
a , b – oraliqni chap va o’ng chegaralari.
Eps – hisoblash aniqligi.
Скачать