Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Const
- maxn = 10;
- Type
- Data = Real;
- Matrix = Array[1..maxn, 1..maxn] of Data;
- Vector = Array[1..maxn] of Data;
- Procedure ReadSystem(n: Integer; var a: Matrix; var b: Vector);
- Var
- i, j, r: Integer;
- Begin
- for j:=1 to n do begin
- for i:=1 to n do read(a[i,j]);
- read(b[j])
- end;
- End;
- Procedure WriteX(n :Integer; x: Vector);
- Var
- i: Integer;
- Begin
- For i := 1 to n do
- Writeln('x', i, ' = ', x[i]);
- End;
- Function Seidel(n: Integer; a: Matrix; b: Vector; var x: Vector; e: Data)
- :Boolean;
- Var
- i, j: Integer;
- s1, s2, s, v, m: Data;
- Begin
- For i := 1 to n do begin
- s := 0;
- For j := 1 to n do
- If j <> i then
- s := s + Abs(a[i, j]);
- If s >= Abs(a[i, i]) then begin
- Seidel := false;
- Exit;
- end;
- end;
- Repeat
- m := 0;
- For i := 1 to n do begin
- s1 := 0;
- s2 := 0;
- For j := 1 to i - 1 do
- s1 := s1 + a[i, j] * x[j];
- For j := i to n do
- s2 := s2 + a[i, j] * x[j];
- v := x[i];
- x[i] := x[i] - (1 / a[i, i]) * (s1 + s2 - b[i]);
- If Abs(v - x[i]) > m then
- m := Abs(v - x[i]);
- end;
- Until m < e;
- Seidel := true;
- End;
- Var
- n, i: Integer;
- a: Matrix;
- b, x: Vector;
- e: Data;
- Begin
- Writeln('Linear Equations Solution using Seidel Method...');
- Writeln('Enter the number of equations:');
- Repeat
- Read(n);
- Until (n > 0) and (n <= maxn);
- Writeln('Enter the approximation level E:');
- Repeat
- Read(e);
- Until (e > 0) and (e < 1);
- Writeln('Enter the extended matrix A:');
- ReadSystem(n, a, b);
- Writeln;
- For i := 1 to n do
- x[i] := 0;
- If Seidel(n, a, b, x, e) then begin
- Writeln('Calculations resulted in...');
- WriteX(n, x);
- end
- else
- Writeln('Seidel`s method is not applicable to this system...');
- Writeln;
- read(n)
- End.
Add Comment
Please, Sign In to add comment