Amaliy ishi Guruh : 652-21 Bajardi : Ziyodulloyev Tekshirdi : Aliqulov Yolqin 25-variant


Download 40.5 Kb.
Sana17.06.2023
Hajmi40.5 Kb.
#1537679
Bog'liq
1682880137 (1)


O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARNI VA KOMMUNIKATSIYANI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Algoritmlarni loyihalash

Amaliy ishi

Guruh : 652-21


Bajardi : Ziyodullo Ziyodulloyev
Tekshirdi : Aliqulov Yolqin
25-variant
1. Berilgan integral qiymatini: a) to‘g‘ri to‘rtburchaklar; b) trapetsiyalar; c) Simpson usullarida ε=0.001 aniqlikda hisoblang. Aniqlikka erishganlik sharti sifatida |S2n-Sn|<ε tengsizlikdan foydalaning (boshlang‘ich n=10 deb olish mumkin). Natijaga erishish uchun zarur bo‘lgan qadamlar soni va integral taqribiy qiymati chiqariladi. С++ dasturida natijani oling.


To`g`ri tortburchak usuli




To`g`ri tortburchak usuli

#include


#include
using namespace std;

double integral(double a, double b, int n) {


double h = (b-a)/n;
double sum = 0;
for (int i = 0; i < n; i++) {
double x = a + (i+0.5)*h;
sum += ((x*x + x )*log(x));
}
return sum*h;
}

int main() {


double a = 1.0;
double b = 3.0;
int n = 10;
double result = integral(a, b, n);
cout << "Natija: " << result << endl;
return 0;
}



Trapetsiya usuli
#include
#include
#include

using namespace std;

double integral(double a, double b, int n) {
double h = (b-a)/n;
double sum = 0.5*((a*a+a)*log(a) + (b*b+b)*log(b));
for (int i = 1; i < n; i++) {
double x = a + i*h;
sum += (x*x+x)*log(x);
}
return sum*h;
}

int main() {


double a = 1.0;
double b = 3.0;
int n = 10;
double result = integral(a, b, n);
cout << "Natija: " << result << endl;
return 0;}


Simpson usuli
#include
#include
using namespace std;
double integral(double a, double b, int n) {
double h = (b-a)/n;
double sum = ((a*a+a)*log(a) + (b*b+b)*log(b));
for (int i = 1; i < n; i += 2) {
double x = a + i*h;
sum += 4*((x*x+x)*log(x));
}
for (int i = 2; i < n-1; i += 2) {
double x = a + i*h;
sum += 2*((x*x+x)*log(x));
}
return sum*h/3;
}
int main() {
double a = 1.0;
double b = 3.0;
int n = 10;
double result = integral(a, b, n);
cout << "Natija: " << result << endl;
return 0;
}

Vatarlar usuli
#include
#include
using namespace std;

double f(double x)


{
return sin(0.5+x)-2*x+0.5;
}

int main()


{
double a = 0, b = 1, x0, x, e = 0.00001;
int k = 0;
if((3*a*a+4*a+1)*(6*a+4) > 0)
{
x = a;
do
{
x0=x;
x = x0 - f(x0) * (b-x0)/(f(b) - f(x0));
k ++;
}while(abs(x-x0) > e );
}
else
{
x = b;
do
{
x0 = x;
x = a - f(a) * (x0-a)/(f(x0) - f(a));
k++;
}while(abs(x-x0) > e);
}
cout <<"Tenglamaning 1 ta yechimi - (" << x;
cout <<")\nShu yechimga olib boruvchi qadamlar soni : " << k;
cout << "\n" << f(x);
}




Nyuton usuli
#include
#include
using namespace std;
//Newton method programm
double f(double x)
{
return sin(0.5+x)-2*x+0.5;
}

double f0(double x)


{
return cos(0.5+x)-2;
}

int main()


{
double a = 0, b = 1, x0, x, e = 0.00001;
int k = 1;
cin >> x0;
x = x0 - f(x0)/f0(x0);
while(abs(x-x0) > e)
{
x0 = x;
x = x0 - f(x0)/f0(x0);
k++;
}
cout <<"Tenglamaning 1 ta yechimi - (" << x;
cout <<")\nShu yechimga olib boruvchi qadamlar soni : " << k;
cout << "\n" << f(x);
}


Vatarlar usuli
b)
#include
#include
using namespace std;

double f(double x)


{
return x*x*x + 3*x + 1;
}
int main()
{
double a = 1, b = 2, x0, x, e = 0.00001;
int k = 0;
if((3*a*a-6*a+12)*(6*a-6) > 0)
{
x = a;
do
{
x0=x;
x = x0 - f(x0) * (b-x0)/(f(b) - f(x0));
k ++;
}while(abs(x-x0) > e );
}
else
{
x = b;
do
{
x0 = x;
x = a - f(a) * (x0-a)/(f(x0) - f(a));
k++;
}while(abs(x-x0) > e);
}
cout <<"Tenglamaning 1 ta yechimi - (" << x;
cout <<")\nShu yechimga olib boruvchi qadamlar soni : " << k;
cout << "\n" << f(x);
}


Nyuton usuli
#include
#include
using namespace std;
//Newton method programm
double f(double x)
{
return x*x*x + 3*x + 1;
}
double f0(double x)
{
return 3*x*x + 3;
}

int main()


{
double a = 1, b = 2, x0, x, e = 0.00001;
int k = 1;
cin >> x0;
x = x0 - f(x0)/f0(x0);
while(abs(x-x0) > e)
{
x0 = x;
x = x0 - f(x0)/f0(x0);
k++; }
cout <<"Tenglamaning 1 ta yechimi - (" << x;
cout <<")\nShu yechimga olib boruvchi qadamlar soni : " << k;
cout << "\n" << f(x);}

Download 40.5 Kb.

Do'stlaringiz bilan baham:




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