Muhammad Al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti
labaratoriya ishi
4-variant
Fan: Algoritm va loyihalash
Fakultet: Telekomunikatsiya texnologiyalari
Guruh:412-20
Patok: MTH007
Bajardi: Aliev Jamshid
Toshkent – 2022
1.1-topshiriq varianlari
Berilgan integralni Simpson hamda Monte-Karlo usulida hisoblang. Oraliqni bo’linish soni N , hamda sinovlar soni M ko’rsatilgan.
𝑠𝑖𝑛2 (𝑥 + 1) ∙ 𝑒 −𝑥 2 [𝒂, 𝒃]= [0;1] N=14 M=15
Dastur kodi;
#include
#include
#include
using namespace std;
float f(float x)
{
return pow(sin(x+1),2)*pow(exp(1),-(x*x));
}
int i, m; float n,a,b,h,s;
int main(int argc, char *argv []) {
cout<
cout<
cout<<" a= "; cin>>a;
cout<<" b= "; cin>>b;
cout<<" n= "; cin>>n;
h=(b-a)/n; cout<
m= int(n/2); cout<
for (i=1; i<=m; i++){
s+=(f(a+(2*i-2)*h) + 4*f(a+(2*i-1)*h) + f(a+2*i*h));
}
s=s*h/3;
cout<
return 0;
}
Natija:
1.2. Algebraik va transtsendent tenglamalarni yechishda oraliqni teng ikkiga bo’lish, iteratsiya usullari.
5. a) x3 -3x2+2x-4=0
/////Oraliqni ikkiga bo'lish
#include
#include
using namespace std;
double f(double x) {
return pow(x,3)-3*x*x+2*x-4;
}
int main(){
double a,b,c,E;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
cout<<"E= ";
cin>>E;
if (f(a) * f(b) < 0) {
c = (a + b) / 2;
while (abs(f(c)) > E) {
if (f(a) * f(c) < 0) {
b = c;
} else {
a = c;
}
c = (a + b) / 2;
}
cout<<"c = " << c;
} else
cout<<"Oraliqda yechim yo'q";
return 0;
}
b) x2+4sinx=0
///////Oraliqni ikkiga bo'lish b
#include
#include
using namespace std;
double f(double x) {
return pow(x,2)+4*sin(x);
}
int main(){
double a,b,c,E;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
cout<<"E= ";
cin>>E;
if (f(a) * f(b) < 0) {
c = (a + b) / 2;
while (abs(f(c)) > E) {
if (f(a) * f(c) < 0) {
b = c;
} else {
a = c;
}
c = (a + b) / 2;
}
cout<<"c = " << c;
} else
cout<<"Oraliqda yechim yo'q";
return 0;
}
1.3 Tenglamalarni yechishda Nyuton va vatarlar usullari. Yaqinlashish tezligi.
5) 𝑎) 3𝑥 + cos 𝑥 + 1 = 0;
Vatarlar usuli
//////Vatarlar usuli
#include
#include
using namespace std;
double f(double x) {
return 3*x+cos(x)+1;
}
int main(){
double a,b,x,E;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
cout<<"E= ";
cin>>E;
do {
x = a - ((f(a) * (b - a)) / (f(b) - f(a)));
if (f(a) * f(x) <= 0) {
b = x;
} else {
a = x;
}
} while (abs(f(x)) <= E);
cout<<"x = "<return 0;
}
Nyuton (Urinmalar) usuli
/////Urinmalar usuli
#include
#include
using namespace std;
double f(double x) {
return 3*x+cos(x)+1;
}
double f2(double x) {
return 3-sin(x);
}
int main(){
double a,b,x,E;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
cout<<"E= ";
cin>>E;
if (f(a)*f2(a)>0){
x=b;
}else x=a;
do {
x=x-(f(x)/f2(x));
}while (abs(f(x))>E);
cout<<"x = "<return 0;
}
𝑏) 𝑥 3+ 𝑥 − 3 = 0.
////Urinlamar b
#include
#include
using namespace std;
double f(double x) {
return pow(x,3)+x-3;
}
double f2(double x) {
return 3*x*x+1;
}
int main(){
double a,b,x,E;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
cout<<"E= ";
cin>>E;
if (f(a)*f2(a)>0){
x=b;
}else x=a;
do {
x=x-(f(x)/f2(x));
}while (abs(f(x))>E);
cout<<"x = "<return 0;
}
Urinmalar usuli.
#include
#include
using namespace std;
double f(double x) {
return pow(x,3)+x-3;
}
int main(){
double a,b,x,E;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
cout<<"E= ";
cin>>E;
do {
x = a - ((f(a) * (b - a)) / (f(b) - f(a)));
if (f(a) * f(x) <= 0) {
b = x;
} else {
a = x;
}
} while (abs(f(x)) <= E);
cout<<"x = "<return 0;
}
Do'stlaringiz bilan baham: |