package math.matrix;

/**
 * 2D diagonal matrix object d<sub>ij</sub>&isin;&#x211D;, i&ne;j=0
 * with 2 rows and 2 columns
 * @author Daniel Weschke
 */
public class Diagonal2D extends Matrix2D {

	/**
	 * UID
	 */
	private static final long serialVersionUID = 553077525134866149L;

	public Diagonal2D(){
		m = 2;
		n = 2;
		data = new double[2];
	}

	/**
	 * Generate an n-by-n identity matrix.
	 * An m-by-n matrix with ones on the diagonal and zeros elsewhere.
	 * @param n rows/columns
	 * @return n-by-n identity matrix
	 */
	public static Diagonal2D identity(int n){
		int i;
        Diagonal2D c = new Diagonal2D();
        for(i=0; i<n; i++)
        	c.set(i, 1);
        return c;
	}
	
	public void set(int i, double d){
		data[i] = d;
	}

	public String toString(){
		return Matrix2D.diag(data).toString();
	}

	public static void main(String[] args) {
	}

}
