|
1 – Amaliy topshiriq 0151-22 guruh talabasi Bajardi: Nazarov Ravshan Tekshirdi: Raxmonova N. N toshkent 2024
|
Sana | 21.05.2024 | Hajmi | 3,67 Mb. | | #247434 |
Bog'liq 6-variant. 1-amaliy ish va 1-laboratoriya ishi
OʻZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI
VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT
AXBOROT TEXNOLOGIYALARI UNIVERSITETI
1 – Amaliy topshiriq
0151-22 - guruh talabasi
Bajardi:Nazarov Ravshan
Tekshirdi: Raxmonova N. N
Toshkent 2024
a = 0
n=14
a=0
b=1
h = (1-0)/14 = 0.0714286
f(0)= 0.708073
f(1)= 0.304171
4*f(0.0714286)= 3.06704
4*f(0.214286)= 3.35512
4*f(0.357143)= 3.3627
4*f(0.5)= 3.09962
4*f(0.642857)= 2.63223
4*f(0.785714)= 2.05936
4*f(0.928571)= 1.48174
2*f(0.142857)= 1.62211
2*f(0.285714)= 1.69743
2*f(0.428571)= 1.63097
2*f(0.571429)= 1.44284
2*f(0.714286)= 1.17619
2*f(0.857143)= 0.882773
S = 0.679105
f(0.131538)= 0.805096
f(0.45865)= 0.800144
f(0.218959)= 0.839983
f(0.678865)= 0.623405
f(0.934693)= 0.364546
f(0.519416)= 0.761523
f(0.0345721)= 0.738105
f(0.5297)= 0.754069
f(0.00769819)= 0.715006
f(0.0668422)= 0.763397
f(0.686773)= 0.615613
f(0.930436)= 0.368638
f(0.526929)= 0.756102
f(0.653919)= 0.647571
f(0.701191)= 0.601265
f(0.762198)= 0.539126
f(0.0474645)= 0.748543
f(0.328234)= 0.846064
f(0.75641)= 0.545087
f(0.365339)= 0.83863
f(0.98255)= 0.31983
f(0.753356)= 0.54823
f(0.0726859)= 0.767673
f(0.884707)= 0.413578
f(0.436411)= 0.811745
f(0.477732)= 0.789069
f(0.274907)= 0.848375
f(0.166507)= 0.822151
f(0.897656)= 0.400684
f(0.0605643)= 0.758697
f(0.504523)= 0.77187
f(0.319033)= 0.847175
f(0.493977)= 0.778863
f(0.0907329)= 0.780258
f(0.0737491)= 0.76844
f(0.384142)= 0.833094
f(0.913817)= 0.38477
f(0.464446)= 0.796888
f(0.050084)= 0.75061
f(0.770205)= 0.530866
f(0.125365)= 0.801672
f(0.688455)= 0.613947
f(0.629543)= 0.670469
f(0.725412)= 0.57682
f(0.888572)= 0.409717
f(0.306322)= 0.848224
f(0.513274)= 0.765856
f(0.845982)= 0.452763
f(0.841511)= 0.457335
f(0.415395)= 0.821355
f(0.467917)= 0.794892
f(0.178328)= 0.826995
f(0.571655)= 0.721235
f(0.0330538)= 0.736847
f(0.49848)= 0.775912
f(0.748293)= 0.553434
f(0.890737)= 0.407558
f(0.84204)= 0.456793
f(0.212752)= 0.83837
f(0.130427)= 0.804489
f(0.274588)= 0.848359
f(0.414293)= 0.821821
f(0.70982)= 0.592601
f(0.239911)= 0.844424
f(0.31754)= 0.847328
f(0.652059)= 0.649345
f(0.681346)= 0.620966
f(0.387725)= 0.831907
f(0.147533)= 0.813396
f(0.845576)= 0.453177
f(0.955409)= 0.34489
f(0.148152)= 0.8137
f(0.408767)= 0.824103
f(0.564899)= 0.72677
f(0.488515)= 0.782372
f(0.961095)= 0.339572
f(0.199757)= 0.834558
f(0.629269)= 0.670722
f(0.651254)= 0.650111
f(0.803073)= 0.496898
f(0.476432)= 0.789856
f(0.20325)= 0.835641
f(0.901673)= 0.396709
f(0.142021)= 0.81063
f(0.410313)= 0.823474
f(0.885648)= 0.412637
f(0.162199)= 0.820268
f(0.365339)= 0.83863
f(0.135109)= 0.807021
f(0.455307)= 0.80198
f(0.4523)= 0.803603
f(0.931674)= 0.367446
f(0.215248)= 0.839035
f(0.908922)= 0.389569
f(0.86086)= 0.437612
f(0.505956)= 0.770898
f(0.817561)= 0.481944
f(0.462245)= 0.798135
f(0.632739)= 0.667512
f(0.824697)= 0.474594
f(0.702207)= 0.600248
f(0.954415)= 0.345823
f(0.289316)= 0.848739
f(0.514435)= 0.765044
f(0.414028)= 0.821932
f(0.876566)= 0.421744
f(0.729748)= 0.572407
f(0.715642)= 0.586726
f(0.706535)= 0.595905
f(0.0190924)= 0.725014
f(0.524987)= 0.757516
f(0.0651939)= 0.762174
f(0.488943)= 0.7821
f(0.682049)= 0.620274
f(0.916634)= 0.382019
f(0.890019)= 0.408275
f(0.139195)= 0.809173
f(0.989362)= 0.313673
f(0.446023)= 0.806908
f(0.514659)= 0.764887
f(0.439726)= 0.810108
f(0.80665)= 0.493203
f(0.211519)= 0.838034
f(0.153604)= 0.816327
f(0.61635)= 0.68252
f(0.000878999)= 0.708872
f(0.727335)= 0.574864
f(0.417724)= 0.820356
f(0.680562)= 0.621737
f(0.83642)= 0.46255
f(0.828708)= 0.470469
f(0.0817376)= 0.774103
f(0.629572)= 0.670443
f(0.213547)= 0.838584
f(0.388823)= 0.831535
f(0.947545)= 0.3523
f(0.269215)= 0.848028
f(0.284035)= 0.848691
f(0.783865)= 0.516753
f(0.282156)= 0.84865
Sum = 94.4224
Monte Carlo usulinatijasi : 0.674446
Misol
grafik
Dastur natijasi:
a = 2
b = 3
|f(2.5)| = 2.125
f(a) * f(b) = -4 * 2 = -8 < 0
a = 2.5
c = (a+b)/2 = (5.5)/2 = 2.75
|f(2.75)| = 0.390625
f(a) * f(b) = -2.125 * 2 = -4.25 < 0
a = 2.75
c = (a+b)/2 = (5.75)/2 = 2.875
|f(2.875)| = 0.716797
f(a) * f(b) = 0.390625 * 2 = 0.78125 > 0
b = 2.875
c = (a+b)/2 = (5.625)/2 = 2.8125
|f(2.8125)| = 0.141846
f(a) * f(b) = 0.390625 * 0.716797 = 0.279999 > 0
b = 2.8125
c = (a+b)/2 = (5.5625)/2 = 2.78125
|f(2.78125)| = 0.129608
f(a) * f(b) = -0.390625 * 0.141846 = -0.0554085 < 0
a = 2.78125
c = (a+b)/2 = (5.59375)/2 = 2.79688
|f(2.79688)| = 0.0048027
f(a) * f(b) = 0.129608 * 0.141846 = 0.0183844 > 0
b = 2.79688
c = (a+b)/2 = (5.57812)/2 = 2.78906
|f(2.78906)| = 0.0627303
f(a) * f(b) = -0.129608 * 0.0048027 = -0.00062247 < 0
a = 2.78906
c = (a+b)/2 = (5.58594)/2 = 2.79297
|f(2.79297)| = 0.0290459
f(a) * f(b) = -0.0627303 * 0.0048027 = -0.000301275 < 0
a = 2.79297
c = (a+b)/2 = (5.58984)/2 = 2.79492
|f(2.79492)| = 0.0121421
f(a) * f(b) = -0.0290459 * 0.0048027 = -0.000139499 < 0
a = 2.79492
c = (a+b)/2 = (5.5918)/2 = 2.7959
|f(2.7959)| = 0.00367485
f(a) * f(b) = -0.0121421 * 0.0048027 = -5.83151e-05 < 0
a = 2.7959
c = (a+b)/2 = (5.59277)/2 = 2.79639
|f(2.79639)| = 0.000562642
f(a) * f(b) = 0.00367485 * 0.0048027 = 1.76492e-05 > 0
b = 2.79639
c = (a+b)/2 = (5.59229)/2 = 2.79614
|f(2.79614)| = 0.00155643
f(a) * f(b) = -0.00367485 * 0.000562642 = -2.06762e-06 < 0
a = 2.79614
c = (a+b)/2 = (5.59253)/2 = 2.79626
|f(2.79626)| = 0.000496972
f(a) * f(b) = -0.00155643 * 0.000562642 = -8.7571e-07 < 0
a = 2.79626
c = (a+b)/2 = (5.59265)/2 = 2.79633
|f(2.79633)| = 3.28146e-05
f(a) * f(b) = 0.000496972 * 0.000562642 = 2.79617e-07 > 0
b = 2.79633
c = (a+b)/2 = (5.59259)/2 = 2.7963
|f(2.7963)| = 0.000232084
f(a) * f(b) = -0.000496972 * 3.28146e-05 = -1.63079e-08 < 0
a = 2.7963
c = (a+b)/2 = (5.59262)/2 = 2.79631
|f(2.79631)| = 9.96359e-05
f(a) * f(b) = -0.000232084 * 3.28146e-05 = -7.61574e-09 < 0
a = 2.79631
c = (a+b)/2 = (5.59264)/2 = 2.79632
|f(2.79632)| = 3.3411e-05
f(a) * f(b) = -9.96359e-05 * 3.28146e-05 = -3.26951e-09 < 0
a = 2.79632
c = (a+b)/2 = (5.59264)/2 = 2.79632
1- funksiyani ildiz: 2.79632
Qadamlar soni: 17
Dastru kodi:
#include
#include
using namespace std;
double f(double x)
{
return pow(x, 3) - 3 * pow(x, 2) + 2 * x - 4;
}
int main() {
double a;
double b;
A: cout << "a = "; cin >> a;
cout << "b = "; cin >> b;
int i=0;
double epsilon = 1e-6; // Ma'lumotning aniqligi
double c = (a + b) / 2.0;
if(f(a) * f(b) < 0)
while (abs(f(c)) > epsilon) {
cout << "|" << "f(" << c << ")| = " << abs(f(c)) << endl;
if (f(a) * f(c) < 0) {
cout << "\tf(a) * f(b) = " << f(a) << " * " << f(b) << " = " << f(a)*f(b) << " > 0" << endl;
cout << "\tb = " << c << endl;
i++;
b = c;
} else {
cout << "\tf(a) * f(b) = " << f(a) << " * " << f(b) << " = " << f(a)*f(b) << " < 0" << endl;
cout << "\ta = " << c << endl;
a = c;i++;
}
c = (a + b) / 2.0;
cout << "\tc = (a+b)/2 = " << "(" <
}
else {
cout << "Oraliqda ildiz yo'q, boshqa oraliqni kiriting: " << endl;
goto A;
}
cout << "1- funksiyani ildiz: " << c << endl;
cout << "Qadamlar soni: " << i << endl;
return 0;
}
a = -2
b = -1.5
1.|f(-1.75)| = 0.873444 > 0.001
f(a) * f(b) = 0.36281 * -1.73998 = -0.631283 > 0
b = -1.75
c = (a+b)/2 = (-3.75)/2 = -1.875
2.|f(-1.875)| = 0.300718 > 0.001
f(a) * f(b) = 0.36281 * -0.873444 = -0.316894 > 0
b = -1.875
c = (a+b)/2 = (-3.875)/2 = -1.9375
3.|f(-1.9375)| = 0.0198491 > 0.001
f(a) * f(b) = 0.36281 * -0.300718 = -0.109104 < 0
a = -1.9375
c = (a+b)/2 = (-3.8125)/2 = -1.90625
4.|f(-1.90625)| = 0.143255 > 0.001
f(a) * f(b) = 0.0198491 * -0.300718 = -0.00596899 > 0
b = -1.90625
c = (a+b)/2 = (-3.84375)/2 = -1.92188
5.|f(-1.92188)| = 0.0624057 > 0.001
f(a) * f(b) = 0.0198491 * -0.143255 = -0.00284349 > 0
b = -1.92188
c = (a+b)/2 = (-3.85938)/2 = -1.92969
6.|f(-1.92969)| = 0.0214536 > 0.001
f(a) * f(b) = 0.0198491 * -0.0624057 = -0.0012387 > 0
b = -1.92969
c = (a+b)/2 = (-3.86719)/2 = -1.93359
|f(-1.93359)| = 0.000846021 < 0.001
2- funksiyani ildiz: -1.93359
Qadamlar soni: 6
Dastur kodi:
#include
#include
using namespace std;
double f(double x) {
return pow(x, 2) + 4*sin(x);
}
int main() {
double a;
double b;
A: cout << "a = "; cin >> a;
cout << "b = "; cin >> b;
int i=0;
double epsilon = 1e-3; // Ma'lumotning aniqligi
double c = (a + b) / 2.0;
if(f(a) * f(b) < 0)
while (abs(f(c)) > epsilon) {
cout << "|" << "f(" << c << ")| = " << abs(f(c)) << " > " << epsilon << endl;
if (f(a) * f(c) < 0) {
cout << "\tf(a) * f(b) = " << f(a) << " * " << f(b) << " = " << f(a)*f(b) << " > 0" << endl;
cout << "\tb = " << c << endl;
i++;
b = c;
} else {
cout << "\tf(a) * f(b) = " << f(a) << " * " << f(b) << " = " << f(a)*f(b) << " < 0" << endl;
cout << "\ta = " << c << endl;
a = c;i++;
}
c = (a + b) / 2.0;
cout << "\tc = (a+b)/2 = " << "(" <
}
else {
cout << "Oraliqda ildiz yo'q, boshqa oraliqni kiriting: " << endl;
goto A;
}
cout << "|" << "f(" << c << ")| = " << abs(f(c)) << " < " << epsilon << endl;
cout << "2- funksiyani ildiz: " << c << endl;
cout << "Qadamlar soni: " << i << endl;
return 0;
}
Misol
OʻZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI
VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT
AXBOROT TEXNOLOGIYALARI UNIVERSITETI
1- Labaratoriya ishi
0151-22 - guruh talabasi
Bajardi:Nazarov Ravshan
Tekshirdi: Raxmonova N. N
Toshkent 2024
Vatarlar usulida topilgan yechim:
{
c = -0.5
f(-0.5) * f(-1)= -1.4597*0.377583 = -0.551156
c = -0.75
c = -0.625
c = -0.5625
f(-0.5625) * f(-0.625)= -0.0640369*0.158424 = -0.010145
c = -0.59375
f(-0.59375) * f(-0.625)= -0.0640369*0.0475985 = -0.00304806
c = -0.609375
c = -0.601562
f(-0.601562) * f(-0.609375)= -0.0081191*0.0197649 = -0.000160473
c = -0.605469
f(-0.605469) * f(-0.609375)= -0.0081191*0.00582915 = -4.73275e-05
c = -0.607422
c = -0.606445
X = -0.606445
}
Dastur kodi(iteratsiya):
#include
#include
using namespace std;
double f(double x) {
return 3 * x + cos(x) + 1;
}
double f_d(double x) {
return 3 - sin(x);
}
double newton_raphson(double x0, double epsilon, int max_iter) {
double x1 = x0;
for (int i = 0; i < max_iter; i++) {
double fx = f(x1);
cout << "x1 = " << x1 << endl;
cout << "\tf(" << x1 << ")= " << f(x1) << endl;
double fpx = f_d(x1);
cout << "\tf_d(" << x1 << ")= " << f_d(x1) << endl;
double x2 = x1 - fx / fpx;
cout << "\tx2 = x1 - f(x) / f_d(x)= " << x2 << endl;
if (fabs(x2 - x1) < epsilon) {
cout << "|x2 - x1| = " << "| " << x2 << "-(" << x1 << ")| = " << fabs(x2-x1) << " < " << epsilon << endl;
return x2;
}
x1 = x2;
}
return x1;
}
int main() {
double x0 = 0.0;
double epsilon = 0.001;
int max_iter = 1000;
double root = newton_raphson(x0, epsilon, max_iter);
cout << "Thenglamani ildizi: " << root << endl;
return 0;
}
Dastur kodi(vatar):
#include
#include
using namespace std;
double f(double x) {
return 3 * x + cos(x) + 1;
}
double bisection(double a, double b, double epsilon, int max_iter) {
if (f(a) * f(b) >= 0) {
cout << "Xato: f (a) va f (b) qarama-qarshi belgilarga ega bo'lishi kerak!" << endl;
return NAN;
}
double c = a;
for (int i = 0; i < max_iter; i++) {
c = (a + b) / 2;
cout << "c = " << c << endl;
if (f(c) == 0 || (b - a) / 2 < epsilon) {
return c;
}
if (f(c) * f(a) < 0) {
b = c;
cout << "f("<
} else {
a = c;
}
}
return c;
}
int main() {
double a = -1.0;
double b = 0.0;
double epsilon = 0.001;
int max_iter = 1000;
double root = bisection(a, b, epsilon, max_iter);
cout << "The root is approximately " << root << endl;
return 0;
}
Urinma usuli
x1 = 0
f(0)= -3
f_d(0)= 1
x2 = x1 - f(x) / f_d(x)= 3
x1 = 3
f(3)= 27
f_d(3)= 28
x2 = x1 - f(x) / f_d(x)= 2.03571
x1 = 2.03571
f(2.03571)= 7.47198
f_d(2.03571)= 13.4324
x2 = x1 - f(x) / f_d(x)= 1.47945
x1 = 1.47945
f(1.47945)= 1.71762
f_d(1.47945)= 7.5663
x2 = x1 - f(x) / f_d(x)= 1.25244
x1 = 1.25244
f(1.25244)= 0.217023
f_d(1.25244)= 5.70582
x2 = x1 - f(x) / f_d(x)= 1.2144
x1 = 1.2144
f(1.2144)= 0.00538065
f_d(1.2144)= 5.42433
x2 = x1 - f(x) / f_d(x)= 1.21341
|x2 - x1| = | 1.21341-(1.2144)| = 0.000991946 < 0.001
Thenglamani ildizi: 1.21341
Vatarlar usulida yechilishi:{
c = 1.5
f(1.5) * f(1)= -1*1.875 = -1.875
c = 1.25
f(1.25) * f(1)= -1*0.203125 = -0.203125
c = 1.125
c = 1.1875
c = 1.21875
f(1.21875) * f(1.1875)= -0.137939*0.0290222 = -0.00400331
c = 1.20312
c = 1.21094
c = 1.21484
f(1.21484) * f(1.21094)= -0.0133805*0.00776523 = -0.000103903
c = 1.21289
c = 1.21387
Ildiz taxminan 1.21387 ga teng
}
|
| |