## Jakub_2

Hello guy,
is here someone who can help me with programme about Gauss or Gauss Jordan elimination? I need it for calculating of system with linear equations.

Thank you

## gusano79 247

What kind of help do you need? Problems with the algorithm? Locating/using a library?

## Jakub_2

Help with the algorithm..

## gusano79 247

Alright, have you tried writing any code yet? If so, please post it.

Starting at the beginning: How are you representing matrices?

## Jakub_2

I have procedure which takes data from a file and writes them then I have problem with main procedure of Gauss :/ I will post it tomorrow now I need to go sleep gn :)

## Jakub_2

Ok I found I did it bad... Now Im trying to do it right just have 2 days for it... Any help will 100% help me with it..

## Jakub_2

I actually did that but Im not sure if its 100% right..

``````program gauss;
uses crt;
const max=10;
type matrix = array[1..max,1..max] of real;
var a:matrix;
i,j,f,g,e,N,M:integer;
y:real;
c,d:boolean;
inFile : text;
inFileName : string;

var i,j : integer;
begin  i := 1; j := 1;
while not eof(inFile) do
begin
j := 1;
while not eoln(inFile) do
begin
inc(j);
end;
inc(i);
end;
close(inFile);
end;

procedure zero (m:integer; var A:matrix);
var n,k:integer;
z:real;
begin
n:=m;k:=m;
while (A[m,n]=0) and (M<=N) do
begin
m:=m+1;
if A[m,n]<>0 then
for n:=1 to N+1 do
begin
z:=A[m,n];
A[m,n]:=A[k,n];
A[k,n]:=z;
end;
end;
end;

begin
writeln('Name of the input file?: ');
assign(inFile,inFileName);
reset(inFile);
d:=false;
for i:=1 to N-1 do
begin
zero(i,a);
for e:=1 to N-i do
begin
if a[i+e,i]<>0 then
begin
y:=a[i+e,i]/a[i,i]*(-1);
for j:=1 to n+1 do
begin
a[i,j]:=a[i,j]*y;
a[i+e,j]:=a[i+e,j]+a[i,j];
end;
end;
end;
for f:=i to n do
begin
c:=false;
for g:=1 to N do c:=(a[f,g]<>0) or c;
if not(c) then d:=a[f,N+1]=0;
end;
end;
if c then
begin
for j:=n downto 1 do
begin
for e:=j+1 to n do a[j,N+1]:=a[j,N+1]-a[j,e];
a[N+1,j]:=a[j,N+1]/a[j,j];
for i:=1 to j-1 do a[i,j]:=a[i,j]*a[N+1,j];
end;
for j:=1 to n do
writeln('x',j,'= ',a[N+1,j]:4:2);
end
else if d then writeln('The equation has infinitely solutions !')
else writeln('The equation has no solution !');
repeat until keypressed;
end.
``````