/*
* 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;
}
}
|