Muhammad Al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti Algoritmlash va Loyihalash




Download 4,32 Mb.
bet1/2
Sana20.05.2024
Hajmi4,32 Mb.
#246725
  1   2
Bog'liq
G`ulomov Kamron




Muhammad Al-Xorazmiy nomidagi

Toshkent axborot texnologiyalari universiteti

Algoritmlash va Loyihalash




Amaliy ish



Topshirdi: G’ulomov K.
Grupa:010-21

Toshkent – 2024
Variant-3
Biz berilgan variantdan foydalangan holda dastlab quyidagicha n1,n2,n3 larni topib chiqamiz
Variant parametrlarini quyidagicha aniqlang: n1={N/3}+1; n2={N/5}+1; n3={N/7}+1, bu yerda N talabalarning potokdagi nomeri. {N/3} bu N sonini 3 ga bo‘lgandagi qoldig‘i. Misol: N=7 {7/3}=1.
Tenglamani hosil qiling:



1.Tenglamaning yechim joylashgan oralig‘ini toping. Vatarlar usuli yordamida ildizlarni e=10-5 aniqlik bilan hisoblash algoritmini tuzing. Bunday aniqllika erishish uchun zarur qadamlar sonini aniqlang. a=-3; b=-2;


Vatarlar usuli
#include
#include
#include
// Tenglamani aniqlash
double f(double x) {
return pow(x, 3) + pow(x, 2) - 4 * x - 4;
}
// Vatarlar usuli
double secantMethod(double x0, double x1, double tol, int& iterations, int max_iter) {
double x2;
for (iterations = 0; iterations < max_iter; ++iterations) {
double f_x0 = f(x0);
double f_x1 = f(x1);
// Agar aniqlik darajasi yetarli bo'lsa
if (fabs(f_x1) < tol) {
return x1;
}
// Vatarlar usuli formulasi
x2 = x1 - f_x1 * (x1 - x0) / (f_x1 - f_x0);
// Boshlang'ich qiymatlarni yangilash
x0 = x1;
x1 = x2;
}
return x2;
}
int main() {
// Yechim oralig'ini aniqlash uchun bir necha qiymatlarni ko'rib chiqamiz
double x_start = -5;
double x_end = 5;
double step = 0.5;
std::cout << "Oraliqni topish uchun qiymatlarni tekshiramiz:\n";
for (double x = x_start; x <= x_end; x += step) {
std::cout << "f(" << x << ") = " << f(x) << std::endl;
}
// Yechim oralig'ini belgilash
double x0 = -3; // Boshlang'ich qiymat
double x1 = -2; // Boshlang'ich qiymat
double tol = 1e-5; // Aniqlik darajasi
int max_iter = 100; // Maksimal iteratsiya soni
int iterations = 0; // Haqiqiy iteratsiyalar soni
double root = secantMethod(x0, x1, tol, iterations, max_iter);
std::cout << std::fixed << std::setprecision(10);
std::cout << "Ildiz: " << root << std::endl;
std::cout << "Iteratsiyalar soni: " << iterations << std::endl;
return 0;
}


2.Ushbu masalani Nyuton usuli orqali yechish algoritmini tuzing. Ikkala usulda ham yechimlarni oling. Ko‘rib chiqilgan usullar samaradorligini taqqoslang.



#include


#include
#include
// Tenglamani aniqlash
double f(double x) {
return pow(x, 3) + pow(x, 2) - 4* x - 4;
}
// Tenglamaning hosilasini aniqlash
double df(double x) {
return 3 * pow(x, 2) + 2 * x - 4;
}
// Nyuton usuli
double newtonMethod(double x0, double tol, int& iterations, int max_iter) {
double x1;
for (iterations = 0; iterations < max_iter; ++iterations) {
double f_x0 = f(x0);
double df_x0 = df(x0);
if (fabs(f_x0) < tol) {
return x0;
}
x1 = x0 - f_x0 / df_x0;

if (fabs(x1 - x0) < tol) {


return x1;
}
x0 = x1;
}
return x1;
}
// Vatarlar usuli
double secantMethod(double x0, double x1, double tol, int& iterations, int max_iter) {
double x2;
for (iterations = 0; iterations < max_iter; ++iterations) {
double f_x0 = f(x0);
double f_x1 = f(x1);

if (fabs(f_x1) < tol) {


return x1;
}
x2 = x1 - f_x1 * (x1 - x0) / (f_x1 - f_x0);

if (fabs(x2 - x1) < tol) {


return x2;
}
x0 = x1;
x1 = x2;
}
return x2;
}
int main() {
double tol = 1e-5; // Aniqlik darajasi
int max_iter = 100; // Maksimal iteratsiya soni
int iterations = 0; // Haqiqiy iteratsiyalar soni
// Nyuton usuli
double x0_newton = 1; // Boshlang'ich qiymat
double root_newton = newtonMethod(x0_newton, tol, iterations, max_iter);
std::cout << "Nyuton usuli:\n";
std::cout << "Ildiz: " << root_newton << std::endl;
std::cout << "Iteratsiyalar soni: " << iterations << std::endl;
// Vatarlar usuli
double x0_secant = -3; // Boshlang'ich qiymat
double x1_secant = -2; // Boshlang'ich qiymat
iterations = 0; // Iteratsiyalar soni
double root_secant = secantMethod(x0_secant, x1_secant, tol, iterations, max_iter);
std::cout << "Vatarlar usuli:\n";
std::cout << "Ildiz: " << root_secant << std::endl;
std::cout << "Iteratsiyalar soni: " << iterations << std::endl;
return 0;}

O`z- o`zidan ayoni natijalar bir-biriga juda ham yaqin chiqqan

3.Chiziqli dasturlash masalasini hosil qiling:









4.ChDM ni simpleks usulida hisoblang. Topilgan yechimlardan iqtisodiy tahlil o‘tkazing. Tegishli matematik modelni ishlab chiqarishni takomillashtirish bo‘yicha tavsiyalarni shakllantiring.


Simpleks usulda ishlash









F= 48300 x1=6; x2=12 x3=9




Download 4,32 Mb.
  1   2




Download 4,32 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



Muhammad Al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti Algoritmlash va Loyihalash

Download 4,32 Mb.