matrixmaths.java

来自「JAVA 数学程序库 提供常规的数值计算程序包」· Java 代码 · 共 132 行

JAVA
132
字号
package jmathlib.toolbox.jmathlib.matrix._private.Jampack;

/**Set of functions for performing standard maths functions
on a matrix*/
public class MatrixMaths
{
	/**Standard functions - calculates the absolute value
    @return the result as an OperandToken*/
    public static Zmat abs(Zmat a)
    {
        Z[][] C = new Z[a.nr][a.nc];
        for (int yy=0; yy<a.nr; yy++)
        {
                for (int xx=0; xx<a.nc; xx++)
                {
                        C[yy][xx] = new Z(a.get(yy, xx).abs());
                }
        }
        Zmat X = new Zmat(C);
        return X;   	
    }

	/**Standard functions - calculates the exponent
    @return the result as an OperandToken*/
    public static Zmat exp(Zmat a)
    {
        Z[][] C = new Z[a.nr][a.nc];
        for (int yy=0; yy<a.nr; yy++)
        {
                for (int xx=0; xx<a.nc; xx++)
                {
                        C[yy][xx] = a.get(yy, xx).exp();
                }
        }
        Zmat X = new Zmat(C);
        return X;   	
    }

	/**Standard functions - calculates the natural logarythm
    @return the result as an OperandToken*/
    public static Zmat ln(Zmat a)
    {
        Z[][] C = new Z[a.nr][a.nc];
        for (int yy=0; yy<a.nr; yy++)
        {
                for (int xx=0; xx<a.nc; xx++)
                {
                        C[yy][xx] = a.get(yy, xx).log();
                }
        }
        Zmat X = new Zmat(C);
        return X;   	
    }

	/**Standard functions - calculates the logarythm
	@param arg = the base to calculate the log to
    @return the result as an OperandToken*/
    public static Zmat log(Zmat a, Zmat b)
    {        
        Z[][] C = new Z[a.nr][a.nc];
        for (int yy=0; yy<a.nr; yy++)
        {
                for (int xx=0; xx<a.nc; xx++)
                {
                        C[yy][xx] = a.get(yy, xx).log().Div(b.get(yy, xx).log());
                }
        }
        Zmat X = new Zmat(C);
        return X;   	    	
    }

	/**Standard functions - rounds the value down
	@param arg = the base to calculate the log to
    @return the result as an OperandToken*/
    public static Zmat floor(Zmat a)
    {        
        double[][] real = a.getRe();
        double[][] imag = a.getIm();
        for (int yy=0; yy<a.nr; yy++)
        {
                for (int xx=0; xx<a.nc; xx++)
                {
                        real[yy][xx] = java.lang.Math.floor(real[yy][xx]);
                        imag[yy][xx] = java.lang.Math.floor(imag[yy][xx]);
                }
        }
        Zmat X = null;
        try{X = new Zmat(real, imag);}	catch(JampackException e){}
        return X;   	    	
    }

	/**Standard functions - rounds the value up
	@param arg = the base to calculate the log to
    @return the result as an OperandToken*/
    public static Zmat ceil(Zmat a)
    {        
        double[][] real = a.getRe();
        double[][] imag = a.getIm();
        for (int yy=0; yy<a.nr; yy++)
        {
                for (int xx=0; xx<a.nc; xx++)
                {
                        real[yy][xx] = java.lang.Math.ceil(real[yy][xx]);
                        imag[yy][xx] = java.lang.Math.ceil(imag[yy][xx]);
                }
        }
        Zmat X = null;
        try{X = new Zmat(real, imag);}	catch(JampackException e){}
        return X;   	    	
    }

	/**Standard functions - rounds the value to the nearest int
	@param arg = the base to calculate the log to
    @return the result as an OperandToken*/
    public static Zmat round(Zmat a)
    {        
        double[][] real = a.getRe();
        double[][] imag = a.getIm();
        for (int yy=0; yy<a.nr; yy++)
        {
                for (int xx=0; xx<a.nc; xx++)
                {
                        real[yy][xx] = java.lang.Math.rint(real[yy][xx]);
                        imag[yy][xx] = java.lang.Math.rint(imag[yy][xx]);
                }
        }
        Zmat X = null;
        try{X = new Zmat(real, imag);}	catch(JampackException e){}
        return X;   	    	
    }
}	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?