I am trying to perform Gaussian elimination on a matrix in Julia to then extract the solutions in fraction form, rather than decimal. For example, I would want 3/4 rather than 0.75 as a solution.
My current code for row-reducing a matrix and expressing the solutions as decimals is as follows:
using RowEchelon
A = [1 2 3;
4 5 6;
7 8 10]
A_reduced rref(A)
print(A_reduced)
Is there a way I can modify this code to obtain fractions rather than floating-point solutions?
Maybe you're looking for
Rational{Int}.(rand())
on your data either cast the initial matrix
a = Rational{Int}.(A)
3×3 Matrix{Rational{Int64}}:
1 2 3
4 5 6
7 8 10
a[1]
1//1
rref(a)
3×3 Matrix{Rational{Int64}}:
1 0 0
0 1 0
0 0 1
or just the result
Rational{Int}.(rref(A))
3×3 Matrix{Rational{Int64}}:
1 0 0
0 1 0
0 0 1