# Toshkent axborot texnologiyalari

Bog'liq
1-lab ishi Algoritmlash (Kaljanov)

 Muhammad Al-Xorazmiy nomidagi TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI “Telekomunikatsiya texnologiyalari” fakulteti “Algoritmlarni loyihalash” fanidan Laboratoriya ishi 1 Bajardi: Kaljanov Shuxrat Tekshirdi:Mirzayev Anvar 1-laboratoriya ishi topshirig‘i 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) Simpson usuli #include #include using namespace std; int main(){ int n; float a,b,h,x=0,s1=0,s0=1000000; cout<<" a = "; cin>>a; cout<<" b = "; cin>>b; n=10; while(1){ x=0; h=(b-a)/n; for(int i=0 ; i x=a+i*h; if(i==0 or i==n-1) s1+=fabs(cos(x*x+1)*pow((pow(x,3)+3*x+1),1./3)); else if (i%2==0) s1+=4*fabs(cos(x*x+1)*pow((pow(x,3)+3*x+1),1./3)); else s1+=2*fabs(cos(x*x+1)*pow((pow(x,3)+3*x+1),1./3)); } s1*=h/3; if(fabs(s1-s0)<0.001){ cout<< "Javob => " < cout<< "Qadamlar soni => "< break; } else { s0=s1; s1=0; n*=2; } } } To’g’ri to’rtburchak usuli #include #include using namespace std; int main(){ int n; float a,b,h,x=0,s1=0,s0=1000000; cout<<" a = "; cin>>a; cout<<" b = "; cin>>b; n=10; while(1){ x=a; h=(b-a)/n; for(int i=0 ; i s1+=fabs(cos(x*x+1)*pow((pow(x,3)+3*x+1),1./3)); x=(i+1)*h; } s1*=h; if(fabs(s1-s0)<0.001){ cout<< "Javob => " < cout<< "Qadamlar soni => " < break; } else { s0=s1; s1=0; n*=2; } } } Trapeciya usuli #include #include using namespace std; int main(){ int n; float a,b,h,x=0,s1=0,s0=1000000; cout<<" a = "; cin>>a; cout<<" b = "; cin>>b; n=10; while(1){ x=0; h=(b-a)/n; for(int i=0 ; i x=a+i*h; if(i==0 or i==n) s1+=fabs(cos(x*x+1)*pow((pow(x,3)+3*x+1),1./3)); else s1+=2*fabs(cos(x*x+1)*pow((pow(x,3)+3*x+1),1./3)); } s1*=h/2; if(fabs(s1-s0)<0.001){ cout<< "Javob => " < cout<< "Qadamlar soni => " < break; } else { s0=s1; s1=0; n*=2; } } } Download 422.04 Kb.