Example: Matrix Formatting

A simple matrix is printed using the default format with the PrintMatrix class. The PrintMatrixFormat class is then used to change the default format.
using System;
using Imsl.Math;

public class PrintMatrixFormatEx1
{
	public static void  Main(String[] args)
	{
		double[,] a = {{0.0, 1.0, 2.0, 3.0}, 
						{4.0, 5.0, 6.0, 7.0}, 
						{8.0, 9.0, 8.0, 1.0}, 
						{6.0, 3.0, 4.0, 3.0}};
		
		//	Construct a PrintMatrix object with a title
		PrintMatrix p = new PrintMatrix("A Simple Matrix");
		
		//	Print the matrix
		p.Print(a);
		
		//	Turn row and column labels off
		PrintMatrixFormat mf = new PrintMatrixFormat();
		mf.SetNoRowLabels();
		mf.SetNoColumnLabels();
		
		//	Print the matrix
		p.Print(mf, a);
	}
}

Output

A Simple Matrix
   0  1  2  3  
0  0  1  2  3  
1  4  5  6  7  
2  8  9  8  1  
3  6  3  4  3  

A Simple Matrix
              
0  1  2  3  
4  5  6  7  
8  9  8  1  
6  3  4  3  


Link to C# source.