Elmat.java :  » Science » jmatlab » org » jmatlab » toolbox » Java Open Source

Java Open Source » Science » jmatlab 
jmatlab » org » jmatlab » toolbox » Elmat.java
/*
 * Created on Aug 22, 2004
 *
 */
package org.jmatlab.toolbox;

import org.jmatlab.linalg.DefaultComplexImpl;
import org.jmatlab.linalg.IMatrix;
import org.jmatlab.semantic.Interpreter;

/**
 * @author Ali
 *
 */
public class Elmat {

  public static IMatrix EYE(double x) {
    int n = (int)x;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(n, n);
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=n; j++) {
        if (i == j)
          rtn.setMatrixElement(i, j, new DefaultComplexImpl(1, 0));
        else
          rtn.setMatrixElement(i, j, new DefaultComplexImpl(0, 0));
      }
    }
    return rtn;
  }

  public static IMatrix EYE(double x, double y) {
    int m = (int)x;
    int n = (int)y;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(m, n);
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        if (i == j)
          rtn.setMatrixElement(i, j, new DefaultComplexImpl(1, 0));
        else
          rtn.setMatrixElement(i, j, new DefaultComplexImpl(0, 0));
      }
    }
    return rtn;
  }

  public static IMatrix ZEROS(double x) {
    int n = (int)x;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(n, n);
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(0, 0));
      }
    }
    return rtn;
  }

  public static IMatrix ZEROS(double x, double y) {
    int m = (int)x;
    int n = (int)y;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(m, n);
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(0, 0));
      }
    }
    return rtn;
  }

  public static IMatrix ONES(double x) {
    int n = (int)x;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(n, n);
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(1, 0));
      }
    }
    return rtn;
  }

  public static IMatrix ONES(double x, double y) {
    int m = (int)x;
    int n = (int)y;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(m, n);
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(1, 0));
      }
    }
    return rtn;
  }

  public static double RAND() {
    return Math.random();
  }
  
  public static IMatrix RAND(double x) {
    int n = (int)x;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(n, n);
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(Math.random(), 0));
      }
    }
    return rtn;
  }
  
  public static IMatrix RAND(double x, double y) {
    int m = (int)x;
    int n = (int)y;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(m, n);
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(Math.random(), 0));
      }
    }
    return rtn;
  }

  //TODO: Fix following 3 normal random number generators
  public static double RANDN() {
    return Math.random();
  }
  
  public static IMatrix RANDN(double x) {
    int n = (int)x;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(n, n);
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(Math.random(), 0));
      }
    }
    return rtn;
  }
  
  public static IMatrix RANDN(double x, double y) {
    int m = (int)x;
    int n = (int)y;
    IMatrix rtn = Interpreter.getLinearAlgebraFactory().createMatrix(m, n);
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        rtn.setMatrixElement(i, j, new DefaultComplexImpl(Math.random(), 0));
      }
    }
    return rtn;
  }

  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.