How to resolve the algorithm Reduced row echelon form step by step in the PARI/GP programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Reduced row echelon form step by step in the PARI/GP programming language

Table of Contents

Problem Statement

Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this will probably be a two-dimensional array). Built-in functions or this pseudocode (from Wikipedia) may be used: For testing purposes, the RREF of this matrix: is:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Reduced row echelon form step by step in the PARI/GP programming language

Source code in the pari/gp programming language

matrref(M)=
{
	my(s=matsize(M),t=s[1]);
	for(i=1,s[2],
		if(M[t,i]==0, next);
		M[t,] /= M[t,i];
		for(j=1,t-1,
			M[j,] -= M[j,i]*M[t,]
		);
		for(j=t+1,s[1],
			M[j,] -= M[j,i]*M[t,]
		);
		if(t--<1,break)
	);
	M;
}
addhelp(matrref, "matrref(M): Returns the reduced row-echelon form of the matrix M.");

rref(M)={
  my(d=matsize(M));
  if(d[1]+1 != d[2], error("Bad size in rref"), d=d[1]);
  concat(matid(d), matsolve(matrix(d,d,x,y,M[x,y]), M[,d+1]))
};

rref([1,2,-1,-4;2,3,-1,-11;-2,0,-3,22])

  

You may also check:How to resolve the algorithm Ordered words step by step in the Scheme programming language
You may also check:How to resolve the algorithm Optional parameters step by step in the Haskell programming language
You may also check:How to resolve the algorithm Atomic updates step by step in the Ring programming language
You may also check:How to resolve the algorithm Range expansion step by step in the R programming language
You may also check:How to resolve the algorithm Descending primes step by step in the Java programming language