I am trying solve some matrices calculations using the MathNet.Numerics
libraries. It all works fine with double numbers. However now I want to represent numbers as fractions and want to get the answers to the calculations as fractions. How can I do that?
What I am currently doing is this.
var M = Matrix<double>.Build;
var V = Vector<double>.Build;
double [,] x1 = {
{0, 0, 0},
{1.0/2, 0 , 0},
{1.0/2, 1.0, 1.0}
};
var m = M.DenseOfArray(x1);
These fractions gets converted into doubles and the final answer will be in doubles. I want to retain fractions throughout the calculation.
There are no fractions in your code sample. The expression "1.0/2" in C# is not a fraction but another way to write the double literal "0.5d". In fact there is no fraction data type in the .Net framework at all.
The F# extensions of Math.NET Numerics do provide a BigRational type which implements fractions based on BigIntegers, but Math.NET Numerics does not support vectors or matrices of this value type either. Math.NET Symbolics might support this in the future but it's not there yet.