II bob . Algebraik tenglamalar sistemasini yechish usullari algaritimi va dasturi .
2.1 Oddiy iterasiya usuli bilan tenglamalar sistemasini hisoblash.
Noma’lumlar soni ko’p bo’lganda chiziqli tenglamalar sistemasini yechishning Kramer, Gauss, teskari matrisa usullari bilan olinishi ancha murakkab bo’lib qoladi. Bunday hollarda taqribiy sonli usullardan foydalanish ancha samarali hisoblanadi. Shunday usullardan biri oddiy iterasiya usulidir.
Quyidagi tenglamalar sistemasi berilgan bo’lsin.
, i =1,2,...,n (1)
Bu sistema matrisa ko’rinishida quyidagicha yoziladi:
,
Bu yerda
.
(1) da (i=1,n) deb faraz qilamiz.
Tenglamalar sistemasida 1-tenglamani х1 ga nisbatan, 2- tenglamani х2 ga nisbatan, va ohirgisini хn ga nisbatan yechamiz:
(2)
Ushbu
va
Matrisalar yordamida (2) ni quyidagicha yozish mumkin: (3) sistemani ketma-ket yaqinlashish usuli bilan yechamiz.
х(0)=, , ,....
Bu jarayonni quyidagicha ifodalaymiz:
, х(0)= (4)
Bu ketma-ketlikning limiti, agar u mavjud bo’lsa (1) sistemaning yechimi bo’ladi.
Biz
belgilashni kiritamiz. Agar ihtiyoriy >0 uchun tengsizlik barcha i =1,2,...n uchun bajarilsa мулещк (1) sistemaning aniqlikdagi yechimi deb yuritiladi.
Teorema. Agar keltirilgan (2) system uchun yoki shartlardan birortasi bajarilsa, uholda (4) iterasiyon jarayon boshlang’ich yaqinlashishni tanlashga bog’liq bo’lmagan holda yagona yechimga yaqinlashadi.
Natija (4) tenglamalar sistemasi uchun
, , ...,
tengsizliklar bajarilsa (4) iterasiya yaqinlashuvchi bo’ladi.
Misol. Tenglamalar sistemasini =0,001 aniqlikda oddiy iterasiya usuli bilan yeching:
Yechish:
Demak, iterasiya yaqinlashuvchi.
.
Nolinchi yaqinlashish: , .
(4) formula yordamida hisoblashlarni bajaramiz.
Ushbu jadval hosil bo’ladi.
Yaqinlashishlar (k)
|
x1
|
x2
|
x3
|
|
|
|
0
|
2
|
3
|
5
|
-
|
-
|
-
|
1
|
1,92
|
3,19
|
5,04
|
0,08
|
0,19
|
0,04
|
2
|
1,9094
|
3,1944
|
5,0446
|
0,0106
|
0,0044
|
0,0046
|
3
|
1,90923
|
3,19495
|
5,04485
|
0,00017
|
0,00055
|
0,00025
|
Bunda , , bajariladi. x=x(3) ChTS ning taqribiy ildizi.
Tenglamalar sistemasini oddiy iterasiya usulida yechish uchun ABC Pascal algortmik tilida tuzilgan dastur matni.
program iter_sis; uses crt;
label 1,2; const n=3; {tenglamalar coni}
type matrisa=array[1..n,1..n] of real;
vektor=array[1..n] of real;
var a,a1:matrisa; x,x0,b,b1:vektor; eps,s:real; i,j,k:integer;
begin clrscr;
for i:=1 to n do begin
for j:=1 to n do begin write('a[',i:1,',',j:1,']='); read(a[i,j]) end;
write('b[',i:1,']='); read(b[i]); end;
eps:=0.0001; for i:=1 to n do begin
b1[i]:=b[i]/a[i,i];
for j:=1 to n do a1[i,j]:=-a[i,j]/a[i,i] end;
for i:=1 to n do begin
x0[i]:=b1[i]; a1[i,i]:=0; end;
2: for i:=1 to n do Begin s:=0.0;
for j:=1 to n do s:=s+a1[i,j]*x0[j];
x[i]:=b1[i]+s; end; k:=0;
for i:=1 to n do if abs(x[i]-x0[i])
then begin k:=k+1; if k=n then goto 1 end
else begin for j:=1 to n do x0[j]:=x[j]; goto 2 end;
1: writeln('Sistemaning taqribiy yechimi:');
for i:=1 to n do writeln('x[',i:1,']=',x[i]:10:8);
end.
Dastur natijasi
2.2 Zeydel usuli bilan tenglamalar sistemasini hisoblash
Zeydel usuli chiziqli bir qadamli birinchi tartibli ityeratsion usuldir. Bu usul oddiy ityeratsion usuldan shu bilan farq qiladiki, dastlabki yaqinlashish ga ko’ra topiladi. So’ngra ko’ra topiladi va x.k. Barcha lar aniqlangandan so’ng lar topiladi. Aniqroq aytganda, hisoblashlar quyidagi sxema bo’yicha olib boriladi:
Ko’pincha Zeydel usuli oddiy ityeratsiya usuliga nisbatan yaxshiroq yaqinlashadi, ammo har doim ham bunday bo’lavyermaydi. Bundan tashqari Zeydel usuli programmalashtirish uchun qulaydir, chunki ning qiymati hisoblanayotganda larning qiymatini saqlab qolishning hojati yo’q.
Misol. Zeydel usuli bilan misolning yyechimi 5 xona aniqlikda topilsin.
Yechish. Bu tizimning tenglamalarini mos ravishda 10, 25, - 20, 10, 20 larga bo’lib, quyidagi ko’rinishda yozib olamiz:
bu yerda shart bajariladi. Haqiqadan ham,
Dastlabki yaqinlashish x(0) sifatida ozod hadlar ustuni (0,6; 0,44; 0,95; 1; 1,6)
Ityeratsiyaning birinchi qadamini bajaramiz:
x1(1) = 0,6 – 0,1 x2(0) + 0,3x3(0) +0,2x4(0) – 0,1x5(0) =
=0,6 – 0,1 0,44 + 0,3 0,95 + 0,2 1 – 0,1 1,6 = 0,881
x2(1) = 0,44 + 0,04 x1(1) - 0,04x3(0) +0,2x4(0) + 0,08x5(0) =
= 0,44 + 0,04 0,881 - 0,04 0,95 + 0,2 1 – 0,08 1,6 = 0,771
x3(1) = 0,95 + 0,1 x1(1) + 0,05x2(1) +0,1x4(0) – 0,1x5(0) =
= 0,95 + 0,1 0,881 + 0,05 0,771 + 0,1 1 – 0,15 1,6 = 0,937
x4(1) = 1 – 0,1 x2(1) + 0,1x3(1) +0,5x5(0) = 1,817
x5(1) = 1,6 + 0,05x1(1) + 0,1x2(1) + 0,05x3(1) +0,1x4(1) = 1,948
Keyingi yaqinlashishlarni jadvalda keltiramiz:
jadval
K
|
|
|
|
|
|
0
|
0,6
|
0,44
|
0,95
|
1
|
1,6
|
1
|
0.881
|
0,771
|
0,937
|
1,817
|
1,948
|
2
|
0,973
|
0,961
|
0,985
|
1.974
|
1,992
|
3
|
0,995
|
0,995
|
0,999
|
1,996
|
1,999
|
4
|
0,9995
|
0,9991
|
0,9997
|
1,9995
|
1,9998
|
5
|
0,99992
|
0,99989
|
0,99997
|
1.99991
|
1,99997
|
6
|
0,99999
|
0,99998
|
0,99999
|
1,99999
|
2.00000
|
Javob: x1 = x2 = x3 = 1; x4 = x5 = 2
Taqribiy hisoblashlar kompyuter texnologiyasi yordamida oson bajariladi. Buning uchun amaliy dasturlarga yoki dasturlashtirish tillariga murojaat etiladi. Quyida Turbo Paskal dasturlash tilida iteratsiya usuliga tuzilgan dastur matni:
uses crt;
type mat=array[1..20,1..20] of real; vector=array[1..30] of real;
var ag,temp,a,y,b,z,a2: mat; temp2:array[1..20,1..20] of integer;
i,p,q,j,k,n,nn,t: integer; aa,aas,d,m,x,r,bg,x3,x2: vector; ii: integer;
m2,s2,max,l,s,f: real; h: integer;
begin write('Count N='); readln(n);
for i:=1 to n do begin for j:=1 to n do begin
write('a[',i,'][',j,']='); readln(a[i,j]); end;
write('b[',i,']='); readln(a[i,j+1]); end;
For i:=1 To n do For j:=1 To n+1 do a2[i,j]:=a[i,j]/a[i,i];
For i:=1 To n do x[i]:= a2[i,n+1]; repeat
For i:=1 To n do begin s:=a2[i,n+1]; For j:=1 To n do begin
If ji Then s:=s-a2[i,j]*x[j];
end; x2[i]:=x3[i]; x3[i]:=s; end; f:=0; For i:=1 To n do
begin If Abs(x3[i]-x2[i])>0.00001 Then f:=1; x[i]:=x3[i]; end;
until f<>1; writeln('Ziydel ildizlari'); for k:=1 to n do
writeln('X[',k,']=', x[k]:5:5); for t:=1 to n do begin
l:=a[t,t]; for j:=1 to n+1 do a[t,j]:=a[t,j]/l; for i:=t+1 to n do begin l:=a[i,t];
for j:=1 to n+1 do a[i,j]:=a[i,j]-a[t,j]*l ; end;
end;
end.
Yuqorida berilgan tenglamalar sitemasini Ziydel usulida yechishni ABCPascal dasturi yordamida amalga oshiramiz.
Dastur matni.
Dastur natijasi :
Ziydel usuliga tuzilgan algoritm blok – sxemasi:
Xulosa
Kurs ishi davomida algebraic tenglamalar sistemasini yechish usullari va ularning algarimlarini tuzishni o’rgandim .chiziqli tenglamalar sistemasining gaoss krame usullari algaritmi yordamida c++ , C# tillarida dastur tuzildi va ilovada berildi. Dasturda algaritimi takrorlash sikllari va hisoblash amallariga asoslangan .
Har ikkala dasturdaham bir hil natijaga erishildi .
Ilova .
Chiziqli tenglamalar sistemasini Gauss usuli yordamida yechish dasturi .
#include
using namespace std;
// Вывод системы уравнений
void sysout(double **a, double *y, int n)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << a[i][j] << "*x" << j;
if (j < n - 1)
cout << " + ";
}
cout << " = " << y[i] << endl;
}
return;
}
double * gauss(double **a, double *y, int n)
{
double *x, max;
int k, index;
const double eps = 0.00001; // точность
x = new double[n];
k = 0;
while (k < n)
{
// Поиск строки с максимальным a[i][k]
max = abs(a[k][k]);
index = k;
for (int i = k + 1; i < n; i++)
{
if (abs(a[i][k]) > max)
{
max = abs(a[i][k]);
index = i;
}
}
// Перестановка строк
if (max < eps)
{
// нет ненулевых диагональных элементов
cout << "Решение получить невозможно из-за нулевого столбца ";
cout << index << " матрицы A" << endl;
return 0;
}
for (int j = 0; j < n; j++)
{
double temp = a[k][j];
a[k][j] = a[index][j];
a[index][j] = temp;
}
double temp = y[k];
y[k] = y[index];
y[index] = temp;
// Нормализация уравнений
for (int i = k; i < n; i++)
{
double temp = a[i][k];
if (abs(temp) < eps) continue; // для нулевого коэффициента пропустить
for (int j = 0; j < n; j++)
a[i][j] = a[i][j] / temp;
y[i] = y[i] / temp;
if (i == k) continue; // уравнение не вычитать само из себя
for (int j = 0; j < n; j++)
a[i][j] = a[i][j] - a[k][j];
y[i] = y[i] - y[k];
}
k++;
}
// обратная подстановка
for (k = n - 1; k >= 0; k--)
{
x[k] = y[k];
for (int i = 0; i < k; i++)
y[i] = y[i] - a[i][k] * x[k];
}
return x;
}
int main()
{
double **a, *y, *x;
int n;
system("chcp 1251");
system("cls");
cout << "Введите количество уравнений: ";
cin >> n;
a = new double*[n];
y = new double[n];
for (int i = 0; i < n; i++)
{
a[i] = new double[n];
for (int j = 0; j < n; j++)
{
cout << "a[" << i << "][" << j << "]= ";
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++)
{
cout << "y[" << i << "]= ";
cin >> y[i];
}
sysout(a, y, n);
x = gauss(a, y, n);
for (int i = 0; i < n; i++)
cout << "x[" << i << "]=" << x[i] << endl;
cin.get(); cin.get();
return 0;
}
Chiziqli tenglamalar sistemasini Kramer usuli yordamida yechish dasturi.
#include
using namespace std;
int determinant(int matrix[3][3]);
int determinantX1(int coefMatrix[3][3], int constTermsMatrix[3]);
int determinantX2(int coefMatrix[3][3], int constTermsMatrix[3]);
int determinantX3(int coefMatrix[3][3], int constTermsMatrix[3]);
int main()
{
int i, j;
int coefficientsMatrix3x3[3][3];
int constantTermsMatrix3x1[3];
cout << "Vvedite koefficienty i sbobodnye chleny " << endl;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
cout << "a[ " << i << "," << j << "]= ";
cin >> coefficientsMatrix3x3[i][j];
}
cout << "b,[ " << i << "]= ";
cin >> constantTermsMatrix3x1[i];
}
int det = determinant(coefficientsMatrix3x3);
int detX1 = determinantX1(coefficientsMatrix3x3, constantTermsMatrix3x1);
int detX2 = determinantX2(coefficientsMatrix3x3, constantTermsMatrix3x1);
int detX3 = determinantX3(coefficientsMatrix3x3, constantTermsMatrix3x1);
if (det != 0)
{
cout << "X1 = " << (float)detX1/(float)det << endl;
cout << "X2 = " << (float)detX2/(float)det << endl;
cout << "X3 = " << (float)detX3/(float)det << endl;
}
else
cout << "Sistema ne imejet reshenij " << endl << endl;
return 0;
}
int determinant(int matrix[3][3])
{
int a11 = matrix[0][0];
int a12 = matrix[0][1];
int a13 = matrix[0][2];
int a21 = matrix[1][0];
int a22 = matrix[1][1];
int a23 = matrix[1][2];
int a31 = matrix[2][0];
int a32 = matrix[2][1];
int a33 = matrix[2][2];
return (a11 * a22 * a33) + (a12 * a23 * a31) + (a13 * a21 * a32) -
(a13 * a22 * a31) - (a11 * a23 * a32) - (a12 * a21 * a33);
}
int determinantX1(int coefMatrix[3][3], int constTermsMatrix[3])
{
int a12 = coefMatrix[0][1];
int a13 = coefMatrix[0][2];
int a22 = coefMatrix[1][1];
int a23 = coefMatrix[1][2];
int a32 = coefMatrix[2][1];
int a33 = coefMatrix[2][2];
int c1 = constTermsMatrix[0];
int c2 = constTermsMatrix[1];
int c3 = constTermsMatrix[2];
return (c1 * a22 * a33) + (a12 * a23 * c3) + (a13 * c2 * a32) -
(a13 * a22 * c3) - (c1 * a23 * a32) - (a12 * c2 * a33);
}
int determinantX2(int coefMatrix[3][3], int constTermsMatrix[3])
{
int a11 = coefMatrix[0][0];
int a13 = coefMatrix[0][2];
int a21 = coefMatrix[1][0];
int a23 = coefMatrix[1][2];
int a31 = coefMatrix[2][0];
int a33 = coefMatrix[2][2];
int c1 = constTermsMatrix[0];
int c2 = constTermsMatrix[1];
int c3 = constTermsMatrix[2];
return (a11 * c2 * a33) + (c1 * a23 * a31) + (a13 * a21 * c3) -
(a13 * c2 * a31) - (a11 * a23 * c3) - (c1 * a21 * a33);
}
int determinantX3(int coefMatrix[3][3], int constTermsMatrix[3])
{
int a11 = coefMatrix[0][0];
int a12 = coefMatrix[0][1];
int a21 = coefMatrix[1][0];
int a22 = coefMatrix[1][1];
int a31 = coefMatrix[2][0];
int a32 = coefMatrix[2][1];
int c1 = constTermsMatrix[0];
int c2 = constTermsMatrix[1];
int c3 = constTermsMatrix[2];
return (a11 * a22 * c3) + (a12 * c2 * a31) + (c1 * a21 * a32) -
(c1 * a22 * a31) - (a11 * c2 * a32) - (a12 * a21 * c3);
}
Foydalanilgan adabiyotlar
Claudio Canuto, Anita Tabacco, Mathematical Analysis I, Springer-Verlag Italiya, Milan 2008.
W.WL.Chen Fundamental of analysis , Macquarie university, 2008
Жўраев Т., Саъдуллаев А., Худойберганов Г., Мансуров Х., Ворисов А. Олий математика асослари. Т.1., Тошкент, “Ўқитувчи”, 1995.
Жўраев Т., Саъдуллаев А., Худойберганов Г., Мансуров Х., Ворисов А. Олий математика асослари. Т.2., Тошкент, “Ўзбекистон”, 1999.
Соатов Ё.У Олий математика. Т., Ўқитувчи, 1995. 1- 5 қисмлар.
Колдаев, В. Д Численные методы и программирование [Электронный ресурс]: ИНФРА-М., 2016. – 336 с. (ЭБС Znanium.com). Режим доступа: http://znanium.com/bookread2.php?book=546692
Колдаев, В. Д Основы алгоритмизации и программирования [Электронный ресурс]: ИНФРА-М., 2016. – 416 с. (ЭБС Znanium.com). Режим доступа: http://znanium.com/bookread2.php?book=537513
Г.Шилтд Самоучитель С++. 5-е издание. Санкт-Петербург. “БХВ Петербург” 2010 г.
Do'stlaringiz bilan baham: |