⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elementat.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.jmathlib.matrix;

import jmathlib.core.tokens.numbertokens.DoubleNumberToken;
import jmathlib.core.tokens.Token;
import jmathlib.core.tokens.OperandToken;
import jmathlib.core.tokens.MatrixToken;
import jmathlib.core.functions.ExternalFunction;
import jmathlib.core.interpreter.Errors;

/**An external function to return the element at a certain point of a matrix*/
public class elementat extends ExternalFunction
{
	/**get  the element at a certain point of a matrix
	@param operands[0] = the matrix to sum
	@param operands[1] = the row no
	@param operands[2] = toe column no*/
	public OperandToken evaluate(Token[] operands)
	{
		OperandToken result = null;
		
		if (getNArgIn(operands) != 3)
			throwMathLibException("ElementAt: number of arguments != 3");
		
		int rowNo = ((int)((DoubleNumberToken)operands[1]).getValueRe());
		int colNo = ((int)((DoubleNumberToken)operands[2]).getValueRe());
		
		if(operands[0] instanceof DoubleNumberToken)
		{
			double[][] values = ((DoubleNumberToken)operands[0]).getReValues();
			result = new DoubleNumberToken(values[rowNo][colNo]);
		}
		else if(operands[0] instanceof MatrixToken)
		{
			OperandToken[][] values = ((MatrixToken)operands[0]).getValue();
			result = values[rowNo][colNo];
		}
		else
			Errors.throwMathLibException(ERR_INVALID_PARAMETER, new Object[] {"DoubleNumberToken or MatrixToken", operands[0].getClass().getName()});
		
		return result;
	}
}

/*
@GROUP
matrix
@SYNTAX
element = ELEMENTAT(matrix, rowno, colno)
@DOC
Returns the values in the specified position of the matrix.
@NOTES
@EXAMPLES
ELEMENTAT([1,2;3,4],0,0) = 1
ELEMENTAT([1,2;3,4],1,1) = 4
@SEE

*/

⌨️ 快捷键说明

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