Last active
September 22, 2018 17:01
-
-
Save Underwaterr/68ed6a036cbb5ec2e595 to your computer and use it in GitHub Desktop.
Linear Algebra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Echelon_Form() | |
{ | |
// Go through the first column, looking for something that is not a zero, | |
// Swap it with the first row, & make it a 1. | |
Fraction zero = new Fraction(0); | |
for (int i=0; i<columns; i++) // Going up to down | |
{ | |
// Divide each element along the column by pivot | |
Fraction divisor = new Fraction(A[i][i]); | |
for (int j=i; j<rows; j++) // Left to right, divide each element in the row by pivot | |
if (!(Fraction.Equals(divisor, zero))) | |
A[i][j] = new Fraction(Fraction.Divide(A[i][j], divisor)); | |
for (int h=i+1; h<rows; h++) // From pivot row down | |
{ | |
divisor = Fraction.Multiply(A[h][i], new Fraction(-1)); | |
for (int j=i; j<columns; j++) | |
A[h][j] = new Fraction(Fraction.Add(A[h][j], Fraction.Multiply(divisor, A[i][j]))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment