Const N = 4; Var A:array[1..N,1..N] of real; B,X,AX:array[1..N] of real; i,j:integer; S:real; Begin Randomize; Write('B(',N,'):'); For i:= 1 to N do Begin B[i]:=random(721)-360; Write(' ',B[i]:4) End; WriteLn; Write('X(',N,'):'); For i:= 1 to N do Begin X[i]:=random(721)-360; Write(' ',X[i]:4) End; WriteLn; WriteLn('A(',N,',',N,'):'); For i:= 1 to N do Begin Write(' '); For j:= 1 to N do Begin A[i,j]:=random(721)-360; Write(' ',A[i,j]:4) End; WriteLn; End; WriteLn; Write('AX:'); For i:= 1 to N do Begin AX[i]:=0; For j:= 1 to N do Begin AX[i]:=AX[i]+A[i,j]*X[j]; End; Write(' ',AX[i]) End; WriteLn; Write('AX+B:'); For i:= 1 to N do Begin X[i]:=AX[i]+B[i]; Write(' ',X[i]) End; WriteLn; Write('|Ax+b| = '); S:=0; For i:= 1 to N do Begin S:=S+X[i]*X[i]; End; WriteLn(Sqrt(S)) End.
N = 4;
Var
A:array[1..N,1..N] of real;
B,X,AX:array[1..N] of real;
i,j:integer;
S:real;
Begin
Randomize;
Write('B(',N,'):');
For i:= 1 to N do
Begin
B[i]:=random(721)-360;
Write(' ',B[i]:4)
End;
WriteLn;
Write('X(',N,'):');
For i:= 1 to N do
Begin
X[i]:=random(721)-360;
Write(' ',X[i]:4)
End;
WriteLn;
WriteLn('A(',N,',',N,'):');
For i:= 1 to N do
Begin
Write(' ');
For j:= 1 to N do
Begin
A[i,j]:=random(721)-360;
Write(' ',A[i,j]:4)
End;
WriteLn;
End;
WriteLn;
Write('AX:');
For i:= 1 to N do
Begin
AX[i]:=0;
For j:= 1 to N do
Begin
AX[i]:=AX[i]+A[i,j]*X[j];
End;
Write(' ',AX[i])
End;
WriteLn;
Write('AX+B:');
For i:= 1 to N do
Begin
X[i]:=AX[i]+B[i];
Write(' ',X[i])
End;
WriteLn;
Write('|Ax+b| = ');
S:=0;
For i:= 1 to N do
Begin
S:=S+X[i]*X[i];
End;
WriteLn(Sqrt(S))
End.
Пример:
B(4): -51 179 276 -273
X(4): -272 -261 -57 304
A(4,4):
-169 -94 245 -346
-351 -176 280 1
-193 -330 219 -54
338 -57 -44 -328
AX: -48647 125752 109727 -174263
AX+B: -48698 125931 110003 -174536
|Ax+b| = 246563.556248688