2-Topshiriq n = 10 uchun chap va o'ng to'rtburchaklar formulalari yordamida integralni hisoblang, olingan natijalarni taqqoslash orqali aniqlikni baholash


Download 411.06 Kb.
Sana13.05.2023
Hajmi411.06 Kb.
#1457469
Bog'liq
Algorithm 14


O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA
KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Kompyuter injiniring fakulteti



Algoritmlarni loyihalash fanidan


Amaliy ishi
Guruh: 241-21
Bajardi: To’ychiev Javohir
Tekshirdi: Nasriddinov Saloxiddin

Toshkent 2023


1. Matritsalar ustida amallarni bajaring.

#include


#include
#include
using namespace std;
vector calculateExpression(vector& A, vector& B) {
vector result;
int n = A.size();
for (int i = 0; i < n; i++) {
int a = A[i];
int b = B[i];
int temp = a*(2*a+b)-b*(a-b);
result.push_back(temp);
}
return result;
}
int main() {
vector A = {2,3,1,4,-1,0,0,1,2};
vector B = {9,8,7,2,7,3,4,3,5};
vector result = calculateExpression(A, B);
cout << "Natija: ";
for (int i = 0; i < result.size(); i++) {
cout << result[i] << " ";
}
cout << endl;
return 0;
}

2-Topshiriq . n = 10 uchun chap va o'ng to'rtburchaklar formulalari yordamida integralni hisoblang, olingan natijalarni taqqoslash orqali aniqlikni baholash.

#include

#include


using namespace std;

double f(double x) {

return sqrt(1.5*x+2.3)/3+sqrt(0.3*x+1);
}

int main() {


int n = 10;
double a = 0.8;
double b = 2.4;
double h = (b - a) / n;

double sumLeft = 0.0;


for (int i = 0; i < n; i++) {
double xi = a + i * h;
sumLeft += f(xi) * h;
}

double sumRight = 0.0;


for (int i = 1; i <= n; i++) {
double xi = a + i * h;
sumRight += f(xi) * h;
}

cout << "Chap tortburchak : " << sumLeft << endl;


cout << "O'ng tortburchak: " << sumRight << endl;

return 0;


}
3-Topshiriq Trapetsiya formulasi yordamida integralni hisoblang(E=0.001). 2. n=8 uchun Simpson formulasi yordamida integralni hisoblang; jadvalini tuzish orqali natijaning xatosini baholang

#include


#include
using namespace std;

double f(double x) {


return 1/sqrt(x*x+2.5);
}

int main() {


double a = 1.6;
double b = 2.2;
double E = 0.001;
double I = 0.0;
double I_old = 0.0;
int n = 1;
double h = (b-a)/n;

do {
I_old = I;


I = (f(a) + f(b))/2.0;
for (int i = 1; i < n; i++) {
double x = a + i*h;
I += f(x);
}
I *= h;
n *= 2;
h = (b-a)/n;
} while (abs(I - I_old) >= E);

cout << "Integralning yaqinlashishi: " << I << endl;


cout << "Subintervallar soni: " << n << endl;

return 0;


}
#include
#include
using namespace std;

double f(double x) {


return (x*x+1)*sin(x-0.5);
}

int main() {


double a = 0.8;
double b = 1.6;
int n = 8;
double h = (b-a)/n;
double sum_odd = 0.0;
double sum_even = 0.0;

for (int i = 1; i < n; i += 2) {


double x = a + i*h;
sum_odd += f(x);
}
for (int i = 2; i < n; i += 2) {
double x = a + i*h;
sum_even += f(x);
}

double I = (h/3.0)*(f(a) + 4.0*sum_odd + 2.0*sum_even + f(b));

double error = abs(I - 0.462985);
cout << "Integralning yaqinlashishi: " << I << endl;
cout << "Absolute xatoligi: " << error << endl;

return 0;


}

4-Topshiriq kesmani ikkiga bo`lish usuli
#include
#include
using namespace std;

double f(double x) {


return exp(-3*x);
}

double enumerate(double x0, double x1, double eps) {


double x = x0;
while (x <= x1) {
if (abs(f(x)) <= eps) {
return x;
}
x += eps;
}
return NAN;
}

double chords(double x0, double x1, double eps) {


double x = x1;
double x_prev = x0;
while (abs(x - x_prev) > eps) {
x_prev = x;
x -= f(x)*(x - x0)/(f(x) - f(x0));
}
return x;
}

int main() {


double x0 = 0.0;
double x1 = 1.0;
double eps = 0.0001;

double root_enum = enumerate(0, 1, eps);


if (!isnan(root_enum)) {
cout << "Koren naydenniy pereborom: " << root_enum << endl;
} else {
cout << "Koren ne nayden pereborom" << endl;
}

double root_chords = chords(x0, x1, eps);


cout << "Konen naydenniy xordoy: " << root_chords << endl;

return 0;


}

5-Topshiriq Ch.P.M. grafik va simpleks usulida yeching






Simpleks







Xulosa qilib aytganda, chiziqli dasturlash - bu talablar chiziqli munosabatlar bilan ifodalangan matematik modellarni echishning kuchli usuli. Bu matematik dasturlashning alohida holati bo'lib, chiziqli tenglik va chiziqli tengsizlik cheklovlariga bog'liq bo'lgan chiziqli maqsad funksiyasini optimallashtirishni o'z ichiga oladi. Chiziqli dasturlash algoritmlari chiziqli tengsizliklar tizimi bilan aniqlangan qavariq politopning mumkin bo'lgan hududida optimal nuqtani topadi. Chiziqli dasturlash masalalari resurslarni taqsimlash muammolari, foyda-xarajatlarni almashtirish muammolari va qat'iy talablar muammolarini hal qilish uchun ishlatilishi mumkin. Chiziqli dasturlash masalalarini echish uchun ishlatilishi mumkin bo'lgan har xil turdagi hal qiluvchilar mavjud va hal qiluvchi tanlash hal qilinayotgan aniq masalaga bog'liq. Umuman olganda, chiziqli dasturlash qaror qabul qilish va optimallashtirish uchun qimmatli vosita bo'lib, u biznes, muhandislik va boshqa sohalarda ko'plab amaliy dasturlarga ega.

Download 411.06 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling