. , , ,

,,,

():

1.         ( ).

2.         .

3.         .

: , (), Borland C++ Builder 6.



 

, . , . , , . .

, . : ( ), , .

.

c Ax = f (1), A = [aij] (i, j = 1, 2, m) ; x = (x1, x2, x3, xm) , f . (1) : (2) i=1, 2,, m, , , aii 0.

0, . i=1 : (3). (2), : , (n=0, 1, , n0, i=1, 2, , m) (4).

(i=0, 1, , m) ( , random). n0, : , >0. (4) .

x1(0), x2(0),, xm(0), x1(1), x2(1),, xm(1),, x1(k), x2(k),, xm(k) , , (2).

(1) , A , , i=1, 2, , m.

, . , (k+1)  xi (k+1)  (x1 x2,, xi-1).

: (i = 1, 2, n) (5). x1(0), x2(0),, xn(0), - x1, x2, x3,, xn.

, k- , (k+1) :


k=0,1,2,... (6)

 



(5) , (6) , : .

3 .

w.

, (7), w (0<w<2). w . , , .

, .

(7) : (8) .

(8) => . .

, (i+10 ) , k<j i+1 , k<j-i .

()

 

Borland C++ Builder 6 ( nxn). :

, , . , , .. , . , . , . =0,000001. 16, 9.

, w. w=1, 9, 1 , .

(k) w:

w 0.1 0.4 0.8 0.9 1 1.1 1.2 1.3 1.7 1.9
k 16 15 14 13 9 13 14 15 16 16

, , , , .

 

 

 //

#include <vcl.h>

#pragma hdrstop

#include Unit1.h

 //

#pragma package (smart_init)

#pragma resource *.dfm

#include<math.h>

#include<stdlib.h>

TForm1 *Form1;

int n=0, prov=0, k=0;

const x=100;

float A[x] [x], B[x] [x];

float C[x], Y[x];

float *X;

bool fl1=false;

float e;

float v_sh;

 //

__fastcall TForm1:TForm1 (TComponent* Owner)

: TForm(Owner)

{

}

 //


void __fastcall TForm1: ButtonOkClick (TObject *Sender)

{

Memo1->Lines->Clear();

k=0;

TryStrToInt (Edit1->Text, n);

if (n>1)

{

StringGrid1->Enabled=true;

StringGrid1->RowCount=n;

StringGrid1->ColCount=n+1;

ButtonClear->Enabled=true;

ButtonOk->Enabled=false;

StringGrid1->Color=clWindow;

ButtonYakobi->Enabled=true;

ButtonZeydel->Enabled=true;

ButtonRelax->Enabled=true;

X=new float[n];

for (int i=0; i<n; i++)

{

for (int j=0; j<n+1; j++)

{

A[i] [j]=NULL;

}

X[i]=NULL;

}

}

else

{

ShowMessage ( !);

}

}

 //

 

void __fastcall TForm1: ButtonClearClick (TObject *Sender)

{

StringGrid1->Enabled=false;

StringGrid1->RowCount=0;

StringGrid1->ColCount=0;

ButtonClear->Enabled=false;

ButtonOk->Enabled=true;

StringGrid1->Color=clBtnFace;

ButtonYakobi->Enabled=false;

}

 //

void __fastcall TForm1: ButtonYakobiClick (TObject *Sender)

{

 //TryStrToFloat (Edit2->Text, e);

Memo1->Lines->Clear();

e=StrToFloat (Edit2->Text);

for (int i=0; i<n; i++)

{

for (int j=0; j<n+1; j++)

{

TryStrToFloat (StringGrid1->Cells[j] [i], A[i] [j]);

}

}

for (int i=0; i<n; i++)

{

for (int j=0; j<n+1; j++)

{

if (A[i] [j]==NULL)

{

ShowMessage (! !);

fl1=true;

i=n;

break;

}

}

}

if(! fl1) {

for (int i=0; i<n; i++)

{

for (int j=0; j<n; j++)

{

if (i!=j) B[i] [j]=(-1)*A[i] [j]/A[i] [i];

else

{

B[i] [j]=0;

C[i]=A[i] [n]/A[i] [i];

}

}

}

for (int i=0; i<n; i++) X[i]=C[i];

float s=0;

k=0;

do

{

prov=0;

for (int i=0; i<n; i++)

{

Y[i]=X[i];

for (int j=0; j<n; j++)

{

s+=B[i] [j]*X[i];

}

X[i]=s+C[i];

s=0;

}

for (int i=0; i<n; i++)

{

if (fabs(X[i]  Y[i])<e) prov++;

}

k++;

}

while (prov!=n);

Memo1->Lines->Add ( );

Memo1->Lines->Add();

String p=;

Memo1->Lines->Add ( :);

for (int i=0; i<n; i++)

{

p=;

for (int j=0; j<n+1; j++)

{

p+=FloatToStr (B[i] [j])+;

}

Memo1->Lines->Add(p);

}

Memo1->Lines->Add();

Memo1->Lines->Add ( :);

for (int i=0; i<n; i++)

{

if (X[i]!=NULL)

{

Memo1->Lines->Add (x+IntToStr (i+1)+ = +FloatToStr (X[i]));

}

else

{

Memo1->Lines->Add ( !);

break;

}

}

Memo1->Lines->Add();

Memo1->Lines->Add ( = +FloatToStr(k));

}

}

 //

void __fastcall TForm1: ButtonExitClick (TObject *Sender)

{

Close();

}

 //

 

void __fastcall TForm1: RadioButton2Click (TObject *Sender)

{

ButtonYakobi->Visible=false;

ButtonZeydel->Visible=true;

ButtonRelax->Visible=false;

}

 //

 

void __fastcall TForm1: RadioButton1Click (TObject *Sender)

{

ButtonYakobi->Visible=true;

ButtonZeydel->Visible=false;

ButtonRelax->Visible=false;

}

 //

 

void __fastcall TForm1: ButtonZeydelClick (TObject *Sender)

{

Memo1->Lines->Clear();

k=0;

e=StrToFloat (Edit2->Text);

for (int i=0; i<n; i++)

{

for (int j=0; j<n+1; j++)

{

TryStrToFloat (StringGrid1->Cells[j] [i], A[i] [j]);

}

}

for (int i=0; i<n; i++)

{

for (int j=0; j<n+1; j++)

{

if (A[i] [j]==NULL)

{

ShowMessage (! !);

fl1=true;

i=n;

break;

}

}

}

if(! fl1) {

for (int i=0; i<n; i++)

{

for (int j=0; j<n; j++)

{

if (i!=j) B[i] [j]=(-1)*A[i] [j]/A[i] [i];

else

{

B[i] [j]=0;

C[i]=A[i] [n]/A[i] [i];

}

}

}

for (int i=0; i<n; i++)

{

X[i]=rand();

}

k=0;

float s=0;

 

for (int i=0; i<n; i++)

{

for (int j=0; j<n; j++)

{

s+=B[i] [j];

}

Y[i]=s;

s=0;

}

s=Y[0];

for (int i=1; i<n; i++)

{

if (s<Y[i]) s=Y[i];

Y[i]=0;

}

if (s<1)

{

do

{

s=0;

for (int i=0; i<n; i++)

{

Y[i]=X[i];

}

for (int i=0; i<n; i++)

{

s=C[i];

for (int j=0; j<n; j++)

{

s+=X[j]*B[i] [j];

}

X[i]=s;

}

prov=0;

for (int i=0; i<n; i++)

{

if (fabs(X[i]  Y[i])<e) prov++;

}

k++;

}

while (prov!=n);

Memo1->Lines->Add ( );

Memo1->Lines->Add();

String p=;

Memo1->Lines->Add ( :);

for (int i=0; i<n; i++)

{

p=;

for (int j=0; j<n+1; j++)

{

p+=FloatToStr (B[i] [j])+;

}

Memo1->Lines->Add(p);

}

Memo1->Lines->Add();

Memo1->Lines->Add ( :);

for (int i=0; i<n; i++)

{

if (X[i]!=NULL)

{

Memo1->Lines->Add (x+IntToStr (i+1)+ = +FloatToStr (X[i]));

}

else

{

Memo1->Lines->Add ( !);

break;

}

}

Memo1->Lines->Add();

Memo1->Lines->Add ( = +FloatToStr(k));

}

else {Memo1->Lines->Add ( !);}

}

}

 //

 

void __fastcall TForm1: RadioButton3Click (TObject *Sender)

{

ButtonYakobi->Visible=false;

ButtonZeydel->Visible=false;

ButtonRelax->Visible=true;

}

 //

 

void __fastcall TForm1: ButtonRelaxClick (TObject *Sender)

{

 //TryStrToFloat (Edit2->Text, e);

v_sh=StrToFloat (Edit3->Text);

e=StrToFloat (Edit2->Text);

Memo1->Lines->Clear();

k=0;

for (int i=0; i<n; i++)

{

for (int j=0; j<n+1; j++)

{

TryStrToFloat (StringGrid1->Cells[j] [i], A[i] [j]);

}

}

for (int i=0; i<n; i++)

{

for (int j=0; j<n+1; j++)

{

if (A[i] [j]==NULL)

{

ShowMessage (! !);

fl1=true;

i=n;

break;

}

}

}

if(! fl1) {

float vsp=0, alp=0;

for (int i=0; i<n; i++)

{

for (int j=0; j<n; j++)

{

if (i!=j) B[i] [j]=(-1)*A[i] [j]/A[i] [i];

else

{

B[i] [j]=0;

C[i]=A[i] [n]/A[i] [i];

}

}

}

float *sq_z=new float[n];

float *sq_y=new float[n];

for (int i=0; i<n; i++)

{

sq_z[i]=rand();

}

for (int i=0; i<n; i++) sq_y[i]=C[i];

for (int i=0; i<n; i++) X[i]=0;

 

vsp=C[0];

for (int j=0; j<n; j++)

{

vsp+=sq_z[j]*B[0] [j];

}

sq_z[0]=vsp;

 

for (int i=0; i<n; i++)

{

for (int j=0; j<n; j++)

{

vsp+=B[i] [j];

}

Y[i]=vsp;

vsp=0;

}

vsp=Y[0];

for (int i=1; i<n; i++)

{

if (vsp<Y[i]) vsp=Y[i];

Y[i]=0;

}

if (vsp<1)

{

 

do

{

for (int i=0; i<n; i++)

{

Y[i]=X[i];

}

for (int i=0; i<n; i++)

{

vsp=C[i];

for (int j=0; j<n; j++)

{

vsp+=sq_z[j]*B[i] [j];

alp+=B[i] [j]*sq_y[i];

}

sq_z[i]=vsp;

sq_y[i]=alp+C[i];

vsp=0;

alp=0;

X[i]=v_sh*sq_z[i]+(1-v_sh)*sq_y[i];

}

prov=0;

for (int i=0; i<n; i++)

{

if (fabs(X[i]  Y[i])<e) prov++;

}

k++;

}

while (prov!=n);

Memo1->Lines->Add ( );

Memo1->Lines->Add();

String p=;

Memo1->Lines->Add ( :);

for (int i=0; i<n; i++)

{

p=;

for (int j=0; j<n+1; j++)

{

p+=FloatToStr (B[i] [j])+;

}

Memo1->Lines->Add(p);

}

Memo1->Lines->Add();

Memo1->Lines->Add ( :);

for (int i=0; i<n; i++)

{

if (X[i]!=NULL)

{

Memo1->Lines->Add (x+IntToStr (i+1)+ = +FloatToStr (X[i]));

}

else

{

Memo1->Lines->Add ( !);

break;

}

}

Memo1->Lines->Add();

Memo1->Lines->Add ( = +FloatToStr(k));

}

else {Memo1->Lines->Add ( !);}

}

}

 //

 

 

:

0 -0,100000001490 -0,100000001490 0

-0,200000002980 0 -0,100000001490 0

-0,200000002980 -0,200000002980 0 0

 

:

x1 = 1

x2 = 1

x3 = 1,00000011920929

 

= 16

:

0 -0,100000001490 -0,100000001490 0

-0,200000002980 0 -0,100000001490 0

-0,200000002980 -0,200000002980 0 0

 

:

x1 = 1

x2 = 0,99999988079071

x3 = 0,999999940395355

 

= 9

:

0 -0,100000001490 -0,100000001490 0

-0,200000002980 0 -0,100000001490 0

-0,200000002980 -0,200000002980 0 0

 

:

x1 = 1,00000011920929

x2 = 0,99999988079071

x3 = 0,999999940395355

 

w=1

 

= 9

(): 1. ( ). 2. . 3. .

 

 

 

! , , , .
. , :