Вы находитесь на странице: 1из 13

IvanPerez [Type the company name]

[MATH15/B4 PROJECT] [Pick the date]

Gauss-Jordan Elimination is a variant of Gaussian Elimination. Again, we are transforming the coefficient matrix into another matrix that is much easier to solve, and the system represented by the new augmented matrix has the same solution set as the original system of linear equations. In Gauss-Jordan Elimination, the goal is to transform the coefficient matrix into a diagonal matrix, and the zeros are introduced into the matrix one column at a time. We work to eliminate the elements both above and below the diagonal element of a given column in one pass through the matrix. The general procedure for Gauss-Jordan Elimination can be summarized in the following steps:

Example. We will apply Gauss-Jordan Elimination to the same example that was used to demonstrate Gaussian Elimination. Remember, in Gauss-Jordan Elimination we want to introduce zeros both below andabove the diagonal. 1. Write the augmented matrix for the system of linear equations.

[MATH15/B4 PROJECT] [Pick the date]

As before, we use the symbol to indicate that the matrix preceding the arrow is being changed due to the specified operation; the matrix following the arrow displays the result of that change. 2. Use elementary row operations on the augmented matrix [A|b] to transform A into diagonal form.

At this point we have a diagonal coefficient matrix. The final step in Gauss-Jordan Elimination is to make each diagonal element equal to one. To do this, we divide each row of the augmented matrix by the diagonal element in that row. 3. By dividing the diagonal element and the right-handside element in each row by the diagonal element in that row, make each diagonal element equal to one.

[MATH15/B4 PROJECT] [Pick the date]

Hence,

When performing calculations by hand, many individuals choose Gauss-Jordan Elimination over Gaussian Elimination because it avoids the need for back substitution. So we have made a program that is able to perform Gauss-Jordan Elimination in seconds. Heres how it works:

Open MATH15 Gauss-Jordan.htm using any web browser (Google Chrome, Mozilla Firefox, or Safari) or any application that supports .htm files. The program will open along with a prompt that asks you a datum that will be needed to execute the program. Enter the desired number of equations. Then press OK. Enter the desired number of columns. Then press OK. Enter the elements of the first equation as decimals separated by a space, then press OK. (Example: 2x - 3y = -4 would be 2 -3 -4 then OK.) Repeat Step 5 for the other proceeding equations. The program will show a solution making the system of equations to be in reduced-row echelon form.

[MATH15/B4 PROJECT] [Pick the date]

<html> <head> <title>Gauss-Jordan Matrix Solutions Using JavaScript</title> </head> <body> <pre> <script language="javascript"> <!--// document.write("<br>"); document.write("<br>"); document.write("<center>") document.write("MATH15/B4 Project"); document.write("<br>"); document.write("<br>"); document.write("<br>"); document.write("Members:"); document.write("<br>"); document.write("PEREZ, Ivan Czar N."); document.write("<br>"); document.write("GALVEZ, Ralph Marion A."); document.write("<br>"); document.write("TUMBAGA, Anne Marielle"); document.write("<br>"); document.write("<br>"); document.write("<br>"); document.write("</center>") document.write("<br>"); document.write("<br>"); document.write("This program solves a system of linear equations by way of "); document.write("Gauss-Jordan elimination method."); document.write("<br>"); document.write("<br>"); //******************************************************************

[MATH15/B4 PROJECT] [Pick the date] //Function to define array elements; function defineelements(){ lengthofequation=equation[i].length; builder=""; count=0; for(count==0;count<lengthofequation;count++){ builder=equation[i].charAt(count); // document.write(builder+"<br>"); if(builder!=" "){ rowcolumn[i][j]=rowcolumn[i][j]+builder; a[i][j]=parseFloat(rowcolumn[i][j]); //document.write(i+" "+j+" "+rowcolumn[i][j]+"<br>"); //document.write(i+" "+j+" "+a[i][j]+"<br>"); }; if(builder==" "){ j=j+1; }; builder=""; }; };//End of function defineelements; //********************************************************************* function makefirstelement1(){ j=1; for(j==1;j<=numberofcolumns;j++){ a[rowtoone][j]=a[rowtoone][j]/divisor; }; };//End of function firstelement1; //********************************************************************* function multiplyaddtorow(){ jj=1; for(jj==1;jj<=numberofcolumns;jj++){ a[rowtozero][jj]=a[rowtozero][jj]-multiplier*a[rowtoone][jj]; }; };//End of function multiplyaddtorow; //**********************************************************************

[MATH15/B4 PROJECT] [Pick the date] //*** Function printsolution function printsolution(){ i=1;j=1 for(i=1;i<=numberofrows;i=i+1){ for(j=1;j<=numberofcolumns;j=j+1){ if(Math.abs(a[i][j])<=.000001){ a[i][j]=0;//Zero out scientific notation } } } i=1;j=1; for(i=1;i<=numberofrows;i++){ for(j=1;j<=numberofcolumns;j++){ rowcolumn[i][j]=""+a[i][j]+" document.write(rowcolumn[i][j]+" "); if(j==numberofcolumns){ document.write("<br>"); document.write("<br>"); }; }; }; if(rowtoone!=numberofrows){ document.write("NEXT STEP ************************************************"); document.write("*********************"); document.write("<br>"); document.write("<br>"); }; if(rowtoone==numberofrows){ document.write("FINISHED *************************************************"); document.write("*********************"); }; };//End of function printsolution; //********************************************************************** "; rowcolumn[i][j]=rowcolumn[i][j].substring(0,15);

[MATH15/B4 PROJECT] [Pick the date] //******* //Main Body //******* //********************************************************************** numberofequations=prompt("How many equations are there for this system?",""); numberofrows=numberofequations; numberofcolumns=prompt("How many columns are there?",""); equation=new Array(numberofcolumns+1); k=0; //Set all elements to 0.; for(k==0;k<=numberofcolumns+1;k++){ equation[k]=0; }; i=0; j=0; //Set all elements to 0 or to null.; rowcolumn=new Array(numberofrows);//String; a=new Array(numberofrows);//Real number; for(i=0;i<=numberofrows;i++){ //********NOTE: Use i=0 not i==0 for nested loops; rowcolumn[i]=new Array(numberofcolumns); a[i]=new Array(numberofcolumns); for(j=0;j<=numberofcolumns;j++){ rowcolumn[i][j]=""; a[i][j]=0; }; }; pp="Enter the elements of one equation as decimals separated by a space,"; q="\n then press the enter key."; qq="\nExample: 2x - 3y = -4 would be 2 -3 -4 then enter key."; p=pp+q+qq; i=1; for(i==1;i<=numberofequations;i++){ equation[i]=prompt(p,""); };

[MATH15/B4 PROJECT] [Pick the date] //************************************************************************ //Call functions //*** i=1; j=1; for(i==1;i<=numberofequations;i++){ defineelements(); j=1; }; document.write("Step by step solution follows:"); document.write("<br>"); document.write("<br>"); rowtoone=1; printsolution(); //***Row reduced Echelon form follows: rowtoone=1; for(rowtoone=1;rowtoone<=numberofrows;rowtoone++){ columntoone=rowtoone; divisor=a[rowtoone][columntoone]; makefirstelement1(); firstrowbelow=rowtoone+1; rowbelow=firstrowbelow; if(firstrowbelow<=numberofrows){ for(rowbelow=firstrowbelow;rowbelow<=numberofrows;rowbelow++){ columntozero=columntoone; multiplier=a[rowbelow][columntozero]; rowtozero=rowbelow;//Below the row with a one. multiplyaddtorow(); }; }; firstrowabove=rowtoone-1; rowabove=firstrowabove; if(firstrowabove>=1){ for(rowabove=firstrowabove;rowabove>=1;rowabove--){ columntozero=columntoone;

[MATH15/B4 PROJECT] [Pick the date] multiplier=a[rowabove][columntozero]; rowtozero=rowabove;//Above the row with a one. multiplyaddtorow(); };//End of 'for' };//End of 'if' printsolution(); };//End of row reduced Echelon form //--> </script> </pre> </body> </html>

[MATH15/B4 PROJECT] [Pick the date]

[MATH15/B4 PROJECT] [Pick the date]

[MATH15/B4 PROJECT] [Pick the date]

Вам также может понравиться