import java.io.*;
import java.text.*;
import java.util.Locale;

public class matrixoutput
{
public static String toString(double left, int w, int d)
// convert double into a w digit string with d digits in real part  
{
	NumberFormat df=NumberFormat.getInstance(Locale.US);
	df.setMaximumFractionDigits(d);
    df.setMinimumFractionDigits(d);
    df.setGroupingUsed(false);
    String s = df.format(left);
    while (s.length() < w)
      s = " " + s;
    if (s.length() > w)
    {
        s = "";
        for (int i=0; i<w; i++)
          s = s + "-";
    }
    return s;
}

public static String toString(double left)
{return toString(left,25,15);}

public static String toString(double[][] left,int w,int d)
{
//string equivalent of a double matris
int n,m;
String b;
b="";
n=left.length;
m=left[0].length;
for(int i=0;i<n;i++)
  {
  for(int j=0;j<m;j++)
    {
    b=b+toString(left[i][j],w,d);
    }
    b=b+"\n";
  }
return b;
}

public static String toString(double[][] a,double b[],int w,int d)
{//string equivalent of a lineear system of equation
int n,m;
String s;
s="";
n=a.length;
m=a[0].length;
for(int i=0;i<n;i++)
  {
  s+=" |";
  for(int j=0;j<m;j++)
    {
    s+=toString(a[i][j],w,d);
    }
    s+="| "+toString(b[i],w,d)+"| \n";
  }
return s;
}

public static String toString(double[][] a,double b[])
{//string equivalent of a lineear system of equation
return toString(a,b,25,15);
}

public static String toStringT(double[][] left,int w,int d)
{ return toString(Matrix.Transpose(left),w,d);}

public static String toStringT(double[][] left)
{ return toString(Matrix.Transpose(left),15,10);}


public static String toStringT(double[] left)
{
// returns a vertical string representation
// of a double vector
int n,m;
String b;
b="";
n=left.length;
for(int i=0;i<n;i++)
  {
    b=b+toString(left[i])+"\n";
  }
return b;
}

public static String toString(double[] left)
{
// returns a horizontal string representation
// of a double vector
int n,m;
String b;
b="";
n=left.length;
for(int i=0;i<n;i++)
  {
    b=b+toString(left[i])+"\t ";
  }
  b=b+"\n";
return b;
}}
