Algebraik va transtsendent tenglamalar yechimlarini taqribiy usullar bilan toppish


Download 1.89 Mb.
Sana09.11.2023
Hajmi1.89 Mb.
#1759928
Bog'liq
Algoritmlash(T1)


23-Variant


Omonov Fayziddin Komil o’g’li



  1. Algebraik va transtsendent tenglamalar yechimlarini

taqribiy usullar bilan toppish.

23.

Yechim joylashgan [a; b] oraliqni aniqlang vaoraliqni ikkiga bo’lish, vatarlar va urinmalar usuli bilan toping. E=0.001.

a) x­­­­­­­3-2x+7=0
b) 3x+cosx=2


/Ikkiga bo'lish usuli

#include
#include
using namespace std;
float f(float x){ return pow(x,3)-2*x+7;}
float f1(float x){ return 3*pow(x,2)-2;}
float f2(float x){ return 6*x;}
int main()
{double a,b,c,x,e=0.001;
cout <<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
if(f(a)<0&&f(b)>0){
do {c=(a+b)/2;
if(f(a)*f(c)<0){b=c;}
else{a=c;} x=(a+b)/2;}
while(fabs(b-a)>e);
cout<
else{ cout<<" Siz noto'g'ri oraliq tanladingiz!\n Qaytadan urinib ko'ring!"<
return 0;}


///Urunmalar usuli

#include
#include
using namespace std;
float f(float x){ return pow(x,3)-2*x+7; }
float f1(float x){ return 3*pow(x,2)-2;}
float f2(float x){ return 6*x;}
int main()
{int n=0;
double x[n],x2,x1,a,b,e=0.001;
cout <<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
if(f(a)<0&&f(b)>0){ if(f1(a)*f2(a)>0){
do { x1=b;
x1=x2;
x2=x1-f(x1)/f1(x1);}
while(fabs(x2-x1)>e);}
if(f1(a)*f2(a)<0){
do { x1=a;
x1=x2;
x2=x1-f(x1)/f1(x1);}
while(fabs(x2-x1)>e);}
cout<
else
cout<<" Yechim bu oraliqda emas Boshqa oraliq kiriting!!!!";
return 0;}

//Vatarlar usuli

#include
#include
using namespace std;
float f(float x){ return pow(x,3)-2*x+7;}
float f1(float x){ return 3*pow(x,2)-2;}
float f2(float x){ return 6*x;}
int main()
{int n=0;
double x1,x2,a,b,e=0.001;
cout <<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
if(f(a)<0&&f(b)>0){
if(f1(a)*f2(a)<0){
do { x1=b;
x1=x2;
x2=x1-f(x1)*(x1-a)/(f(x1)-f(a));}
while(fabs(x2-x1)>e);}
if(f1(a)*f2(a)>0&&f(a)>0){
do { x1=a;
x1=x2;
x2=x1-(f(x1)*(b-x1))/(f(b)-f(x1));}
while(fabs(x2-x1)>e);}
cout<
else{ cout<<" Yechim bu oraliqda emas Boshqa oraliq kiriting!!!!";}
return 0;}


//Ikkiga bo'lish usuli
#include
#include
using namespace std;
float f(float x) { return 3*x+cos(x)-2;}
float f1(float x){ return 3-sin(x);}
float f2(float x){ return -cos(x);}
int main()
{double a,b,c,x,e=0.001;
cout <<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
if(f(a)<0&&f(b)>0){
do { c=(a+b)/2;
if(f(a)*f(c)<0){ b=c;}
else{
a=c;}
x=(a+b)/2;}
while(fabs(b-a)>e);
cout<
else{ cout<<" Siz noto'g'ri oraliq tanladingiz!\n Qaytadan urinib ko'ring!"<
return 0;}

//Urunmalar usuli

#include
#include
using namespace std;
float f(float x){ return 3*x+cos(x)-2;}
float f1(float x){ return 3-sin(x);}
float f2(float x){ return -cos(x);}
int main()
{int n=0;
double x[n],x2,x1,a,b,e=0.001;
cout <<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
if(f(a)<0&&f(b)>0){ if(f1(a)*f2(a)>0){
do { x1=b;
x1=x2;
x2=x1-f(x1)/f1(x1);}
while(fabs(x2-x1)>e);}
if(f1(a)*f2(a)<0){
do { x1=a;
x1=x2;
x2=x1-f(x1)/f1(x1);}
while(fabs(x2-x1)>e);}
cout<
else cout<<" Yechim bu oraliqda emas Boshqa oraliq kiriting!!!!";
return 0;}


//Vatarlar usuli

#include
#include
using namespace std;
float f(float x){ return 3*x+cos(x)-2;}
float f1(float x){ return 3-sin(x);}
float f2(float x){ return -cos(x);}
int main()
{int n=0;
double x1,x2,a,b,e=0.001;
cout <<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
if(f(a)<0&&f(b)>0){
if(f1(a)*f2(a)<0){
do { x1=b;
x1=x2;
x2=x1-f(x1)*(x1-a)/(f(x1)-f(a));}
while(fabs(x2-x1)>e);}
if(f1(a)*f2(a)>0){
do { x1=a;
x1=x2;
x2=x1-(f(x1)*(b-x1))/(f(b)-f(x1));}
while(fabs(x2-x1)>e);}
cout<
else{ cout<<" Yechim bu oraliqda emas Boshqa oraliq kiriting!!!!";}
return 0;}


2.Aniq integralni sonli hisoblash algoritmi

23.

To’g’ri to’rtburchaklar, trapetsiya va Simpson usullarida hisoblang. N bo’lish soni, E=0.001.



[0;1]

10


//To'rtburchaklar usuli

#include
#include
using namespace std;
float f(double x){ return cos(x*x+1)*pow((x*x+5*x+8),1.0/3);}
int main() { double h,a,b,n=10,summ=0,x;
int i=0;
cout<<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
h=(b-a)/n;
while(i<10 ){x=a+i*h;
summ+=(f(x))*h;
i++;}
cout<<" SUMM = "<
return 0;}



//Trapetsiyalar usuli

#include
#include
using namespace std;
float f(double x ) { return cos(x*x+1)*pow((x*x+5*x+8),1.0/3); }
int main(){ double h,a,b,n=10,summ=0,x;
int i=1;
cout<<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
h=(b-a)/n;
while(i<9){ x=a+i*h;
summ+=(f(x))*h;
i++; }
summ=summ+(a+b-h)*h/2;
cout<<" SUMM = "<
return 0; }




//Simpson usuli

#include
#include
using namespace std;
float f(double x) { return cos(x*x+1)*pow((x*x+5*x+8),1.0/3);}
int main(){ double h,a,b,n=10,summ=0,x;
int i=1,j=2;
cout<<"Oraliqni kiriting! [a;b]\n";
cout<<" a = "; cin>>a;
cout<< " b = "; cin>>b;
h=(b-a)/n;
while(i<9){ x=a+i*h;
summ+=4*(f(x))*h/3;
i=i+2;}
while(j<9){ x=a+j*h;
summ+=2*(f(x))*h/3;
j=j+2;}
summ=summ+(a+b-h)*h/3;
cout<<" SUMM = "<
return 0;}

Download 1.89 Mb.

Do'stlaringiz bilan baham:




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