MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT
AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Fan: Algoritmlarni loyihalash
1-labaratoriya ishi
Bajardi: Qurbonaliyev M.
Tekshirdi: Ravshanov SH.
Guruh: 052-21
1.1 Berilgan integral qiymatini to‘g‘ri to‘rtburchaklar, trapetsiyalar, Simpson
usullarida ε>0 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.
7 -variant
1) Tog`ri turtburchak usuli
Dastur kodi:
#include
#include
using namespace std;
float f(float x) {
return cos(pow(x,2) +1)*pow((pow(x,3)+3*x+1),1/3);
}
int main() {
float a=0,b=2,h,x;
int n=1000;
float s=0;
h=(b-a)/n;
for(int i=0; ix=a+i*h;
s+=f(x+h/2)*h;
}
cout<return 0;
}
Natija:
2) Trapetsiya usuli
Dastur kodi:
#include
#include
using namespace std;
float f(float x) {
return cos(pow(x,2) +1)*pow((pow(x,3)+3*x+1),1/3);
}
int main() {
float a=0,b=2,h;
int n=1000;
float s=0, x[n];
h=(b-a)/n;
for(int i=0; ix[i]=a+i*h;
s+=h*f(x[i]);
}
cout<return 0;
}
Natija:
3) Simpson usuli
Dastur kodi:
#include
#include
using namespace std;
float f(float x) {
return cos(pow(x,2) +1)*pow((pow(x,3)+3*x+1),1/3);
}
int main() {
float a=0,b=2,h;
int n=100;
float s=0, x[n];
h=(b-a)/n;
for(int i=0; ix[i]=a+i*h;
if(i%2==0) s+=2*f(x[i]);
else s+=4*f(x[i]);
s+=h*f(x[i]);
}
cout<<(f(a) + f(b) + s)*h/3;
return 0;
}
Natija:
1.2 Berilgan tenglamaning taqribiy yechimini
ε>0
aniqlikda urinmalar
(Nyuton) va vatarlar usullarida hisoblang. Aniqlikka erishganlik sharti
sifatida
|xn+1-xn|<ε
tengsizlikdan foydalaning. Boshlang‘ich x0ϵ(a;b) olinadi.
Natijada ildiz taqribiy qiymati va zarur bo‘lgan qadamlar soni chiqarilsin.
С++ dasturida natijani oling.
7 -variant
A)
Dastur kodi:
#include
#include
using namespace std;
float f(float x) {
return 2-x-log(x);
}
int main() {
float a=1,b=2,eps=0.001;
int i=0;
if(f(a) + f(b)<0){
while(fabs(a-b) > eps){
if(f(a) * f((a+b)/2)<0) b=(a+b)/2;
else a=(a+b)/2;
i++;
}
cout<<" x = "<<(a+b)/2<soni i= "<}
else cout<<"bu oraliqda yechim mavjud emas";
return 0;
}
Natija:
7 - variant
B)
Dastur kodi:
#include
#include
using namespace std;
float f(float x) {
return pow(x,3)-0.2*pow(x,2)+0.4*x-1.4;
}
int main() {
float a=1,b=2,eps=0.001;
int i=0;
if(f(a) + f(b)<0){
while(fabs(a-b) > eps){
if(f(a) * f((a+b)/2)<0) b=(a+b)/2;
else a=(a+b)/2;
i++;
}
cout<<" x = "<<(a+b)/2<soni i= "<}
else cout<<"bu oraliqda yechim mavjud emas";
return 0;
}
Natija:
|