Muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti nurafshon filiali



Yüklə 33,46 Kb.
tarix06.10.2023
ölçüsü33,46 Kb.
#152735
Bozorov Odilbek


O‘ZBEKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALAR VAZIRLIGI


MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI NURAFSHON FILIALI

Axborot texnologiyalari” kafedrasi




2-mustaqil ish hisoboti
Fan:___________“ Dasturiy injiniringa kirish ”___________________
Guruh: 310-21
Talaba: Bozorov Odilbek
Rahbar: Namunabonu Nosirova
Nurafshon-2023
1-laboratoriya ishi topshirig‘i

    1. Berilgan integral qiymatini to‘g‘ri to‘rtburchaklar, trapetsiyalar, Simpson usullarida ε>0 aniqlikda hisoblang. Aniqlikka erishganlik sharti sifatida |S2n-Sn|


#include
#include
using namespace std;

double f(double x) {


return pow(x*x+x+4, 1.0/3)*sin(x*x+1);
}

double trapezoidal(double a, double b, int n) {


double h = (b-a)/n;
double sum = 0;
for(int i=1; isum += f(a+i*h);
}
return h/2*(f(a)+f(b)+2*sum);
}

double simpson(double a, double b, int n) {


double h = (b-a)/n;
double sum1 = 0;
double sum2 = 0;
for(int i=1; isum1 += f(a+i*h);
}
for(int i=2; isum2 += f(a+i*h);
}
return h/3*(f(a)+f(b)+4*sum1+2*sum2);
}

int main() {


double a = -1;
double b = 1;
int n = 10;
double eps = 0.00001;

double S_n = simpson(a, b, n);


double S_2n = simpson(a, b, 2*n);

while(abs(S_2n-S_n)>=eps) {


S_n = S_2n;
n *= 2;
S_2n = simpson(a, b, 2*n);
}

cout << "Integral qiymati: " << S_2n << endl;


}

    1. Berilgan tenglamaning taqribiy yechimini ε>0 aniqlikda urinmalar (Nyuton) va vatarlar usullarida hisoblang. Aniqlikka erishganlik sharti sifatida |xn+1-xn|

A)#include
#include
using namespace std;

double f(double x) {


return (2-x)*exp(x)-0.5;
}

double df(double x) {


return -exp(x)*(x-3);
}

double newton(double x0, double eps) {


double x = x0;
double delta = f(x)/df(x);
while(abs(delta)>=eps) {
delta = f(x)/df(x);
x -= delta;
}
return x;
}

double bisection(double a, double b, double eps) {


double c = (a+b)/2;
while(abs(b-a)>=eps) {
if(f(c)==0) {
break;
} else if(f(a)*f(c)<0) {
b = c;
} else {
a = c;
}
c = (a+b)/2;
}
return c;
}

int main() {


double a = 2;
double b = 3;
double eps = 0.00001;

double x_n = newton(a, eps);


double x_n1 = x_n + eps + 1;

while(abs(x_n1-x_n)>=eps) {


x_n = x_n1;
x_n1 = x_n - f(x_n)/df(x_n);
}

cout << "Ildiz taqribiy qiymati: " << x_n1 << endl;


int n = ceil(log2((b-a)/eps));


double S_n = (f(a)+f(b))/2*(b-a);
for(int i=1; i<=n; i++) {
double h = (b-a)/pow(2, i);
double sum = 0;
for(int j=1; j<=pow(2, i-1); j++) {
sum += f(a+(2*j-1)*h);
}
S_n /= 2;
S_n += h*sum;
}

cout << "Zarur bo‘lgan qadamlar soni: " << n << endl;


}
B) #include
#include
using namespace std;

double f(double x) {


return pow(x, 3)+3*pow(x, 2)+12*x+3;
}

double df(double x) {


return 3*pow(x, 2)+6*x+12;
}

double newton(double x0, double eps) {


double x = x0;
double delta = f(x)/df(x);
while(abs(delta)>=eps) {
delta = f(x)/df(x);
x -= delta;
}
return x;
}

double bisection(double a, double b, double eps) {


double c = (a+b)/2;
while(abs(b-a)>=eps) {
if(f(c)==0) {
break;
} else if(f(a)*f(c)<0) {
b = c;
} else {
a = c;
}
c = (a+b)/2;
}
return c;
}

int main() {


double a = -1;
double b = 0;
double eps = 0.00001;

double x_n = newton(a, eps);


double x_n1 = x_n + eps + 1;

while(abs(x_n1-x_n)>=eps) {


x_n = x_n1;
x_n1 = x_n - f(x_n)/df(x_n);
}

cout << "Ildiz taqribiy qiymati: " << x_n1 << endl;


int n = ceil(log2((b-a)/eps));


double S_n = (f(a)+f(b))/2*(b-a);
for(int i=1; i<=n; i++) {
double h = (b-a)/pow(2, i);
double sum = 0;
for(int j=1; j<=pow(2, i-1); j++) {
sum += f(a+(2*j-1)*h);
}
S_n /= 2;
S_n += h*sum;
}

cout << "Zarur bo‘lgan qadamlar soni: " << n << endl;


}

Yüklə 33,46 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin