org.lsmp.djep.vectorJep.values.Matrix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jep Show documentation
Show all versions of jep Show documentation
JEP is a Java library for parsing and evaluating mathematical expressions.
The newest version!
/* @author rich
* Created on 07-Jul-2003
*/
package org.lsmp.djep.vectorJep.values;
import org.lsmp.djep.vectorJep.*;
//import JSci.maths.DoubleMatrix;
//import JSci.physics.relativity.Rank1Tensor;
/**
* Represents a matrix.
*
* @author Rich Morris
* Created on 07-Jul-2003
* @version 2.3.0.2 now extends number
* @version 2.3.1.1 Bug with non square matrices fixed.
* @since 2.3.2 Added equals method.
*/
public class Matrix implements MatrixValueI
{
public MatrixValueI copy() {
Matrix tmp = new Matrix(this.rows,this.cols);
tmp.setEles(this);
return tmp;
}
// want package access to simplify addition of matrices
int rows=0;
int cols=0;
Object data[][] = null;
Dimensions dims;
private Matrix() {}
/** Construct a matrix with given rows and cols. */
protected Matrix(int rows,int cols)
{
this.rows = rows;
this.cols = cols;
data = new Object[rows][cols];
dims = Dimensions.valueOf(rows,cols);
}
public static MatrixValueI getInstance(int rows,int cols) {
return new Matrix(rows,cols);
}
/**
* Construct a Matrix from a set of row vectors.
* @param vecs
*/
/*
public Matrix(MVector[] vecs) throws ParseException
{
if(vecs==null) { throw new ParseException("Tried to create a matrix with null row vectors"); }
rows = vecs.length;
if(rows==0) { throw new ParseException("Tried to create a matrix with zero row vectors"); }
// now check that each vector has the same size.
cols = vecs[0].size();
for(int i = 1;i0) sb.append(',');
sb.append('[');
for(int j=0;j0)sb.append(',');
sb.append(data[i][j]);
}
sb.append(']');
}
sb.append(']');
return sb.toString();
}
public Dimensions getDim() { return dims; }
public int getNumEles() { return rows*cols; }
public int getNumRows() { return rows; }
public int getNumCols() { return cols; }
public void setEle(int n,Object value)
{
int i = n / cols;
int j = n % cols;
data[i][j] = value;
}
public void setEle(int i,int j,Object value)
{
data[i][j] = value;
}
public Object getEle(int n)
{
int i = n / cols;
int j = n % cols;
return data[i][j];
}
public Object getEle(int i,int j)
{
return data[i][j];
}
public Object[][] getEles()
{
return data;
}
/** sets the elements to those of the arguments. */
public void setEles(MatrixValueI val)
{
if(!dims.equals(val.getDim())) return;
for(int i=0;i>32));
// int yi = (int)(yl^(yl>>32));
for(int i=0;i