2.2 Laboratoriya topshiriqlari
Quyidagi funksiyani to’rtburchaklar, Trapetsiya va Simpson formulalari yordamida taqribiy hisoblash dasturini tuzing.
dx
3.1 Laboratoriya topshiriqlari
Quyidagi transsendent tenglamani oraliqni teng ikkiga bo’lish vaoddiy iteratsiya usuli yordamida yechimini aniqlovchi dastur tuzing:
3x+cosx+1=0
Oraliqni teng ikkiga bo’lish usuli:
Dastur kodi:
#include #include using namespace std;
double fi(double x)
{ return 3*x*x+x*cos(x)+x;
} int main()
{
double a,b,c,e; cin>>a>>b;
while(fi(a)*fi(b)>0)
{ cin>>a>>b;
}
cout<<"e ga qiymat bering: "; cin>>e;
while(fabs(b-a)>=c)
{ c=(a+b)/2; if(fi(a)*fi(c)<0)
b=c; else
a=c;
} c=(a+b)/2; cout<return 0;
}
Dasturdan natija olish:
Interatsiya usuli:
#include #include using namespace std;
double fi(double x)
{ return 3*x*x+x*cos(x)+x;
} int main()
{
double a,b,c,e; cin>>a>>b; cout<<"e ga qiymat bering: "; cin>>e;
double x1, x2; x1=a; x2=b;
while(fabs(a-x2)>=c)
{
x2=fi(x1); a=x1;
x1=x2;
}
cout<<"x ning qiymati: "<}
3.2 Laboratoriya topshiriqlari
Quyidagi transsendent tenglamani Nyuton va Vatarlar usuli yordamida yechimini aniqlovchi dastur tuzing:
x3-2x2+7x-1=0
Dastur kodi: #include using namespace std; double f(double x)
{ return x*x*x-2*x*x+7*x+1;
}
int main () { int a, b, n=10; cin>>a>>b; double h=(b-a)*1.0/n; double x=a, s=0; for (int i=a; i} s=s+h; cout<return 0;
}
Do'stlaringiz bilan baham: |