This project has moved and is read-only. For the latest updates, please go here.

Print double matrix

Mar 28, 2011 at 6:36 PM
Edited Mar 28, 2011 at 6:49 PM

double[,] m = new double[4,4] { { 1F, 2F, 1F, 3F }, { 4F, 2F, 1F, 3F }, { 1F, 2F, 3F, 1F }, { 32F, 2F, 1F, 17F } };

var teste = new DenseMatrix(m);

Console.WriteLine("m:" + teste.ToString());

normally when i have a double i use ToString("N3") and the "N3" is to definy the number of decimals that i want to print, how can i do this with matrix?!

Mar 29, 2011 at 5:00 AM

>how can i do this with matrix?!

Console.WriteLine(teste.ToString("N3", null));

>double[,] m = new double[4,4] { { 1F, 2F, 1F, 3F }, { 4F, 2F, 1F, 3F }, { 1F, 2F, 3F, 1F }, { 32F, 2F, 1F, 17F } };

you can simplify the above (no need to covert floats to doubles).

var m = new[,]{ { 1.0, 2, 1, 3 }, { 4, 2, 1, 3 }, { 1, 2, 3, 1 }, { 32, 2, 1, 17 } };

Mar 29, 2011 at 5:30 AM
Edited Mar 29, 2011 at 5:30 AM

We could make the null a default value, so this would work:

Console.WriteLine(teste.ToString("N3"));

I'll check in the change in a day or so.