(* :Title: Sistema linealaren Gauss-en ezabapena*)

(* :Author: Carlos Gorria*)

(* :Keywords:
	ezabapen *)

(* :Summary: Sistema linealaren ebazpena Gauss-en ezabapenaren bidez. *)

BeginPackage["Garatu`Gaussezab`"]

Gaussezabapen::usage = 
"gaussezabapen[mat,aske,dim] dim dimentsioko mat.x = aske sistema
linealaren triangularizazioa eta ebazpena Gauss-en ezabapenaren bidez."

Begin[ "`Private`" ]

Unprotect[Gaussezabapen]

Gaussezabapen[mat_,aske_,dim_]:=Module[{matb=mat,askeb=aske,i,j,k,
        ezezagun,pibote},
      ezezagun=MatrixForm[Table[{"x(",i,")"},{i,1,dim}]];
      Print[MatrixForm[matb],ezezagun," = ",
        MatrixForm[askeb]];
      Do[Do[pibote=matb[[j,i]]/matb[[i,i]];
          Do[matb[[j,k]]=0,{k,1,i}];
          Do[matb[[j,k]]=matb[[j,k]]-pibote*matb[[i,k]],{k,i+1,dim}];
          askeb[[j,1]]=askeb[[j,1]]-pibote*askeb[[i,1]],
          {j,i+1,dim}];Print[i,")", urratsa];
        Print[MatrixForm[matb],ezezagun," = ",MatrixForm[askeb]],{i,1,dim-1}];
      askeb[[dim,1]]=askeb[[dim,1]]/matb[[dim,dim]];
      Do[Do[askeb[[i,1]]=askeb[[i,1]]-matb[[i,j]]*askeb[[j,1]],{j,i+1,dim}];
        askeb[[i,1]]=askeb[[i,1]]/matb[[i,i]],{i,dim-1,1,-1}];
      Print["Soluzioa:"];Print[ezezagun," = ",MatrixForm[askeb]];];

Protect[Gaussezabapen]

End[ (* "`Private`" *) ];

EndPackage[]   (* Garatu`Gaussezab` *)

(*:Limitations:
*)

(*:Tests:
*)

(*:Examples:

mat={{1,2,-4},{-2,3,2},{6,1,-5}};aske={-1,3,2};dim=3;

Gaussezabapen[mat,aske,dim]
*)
