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

📄 linspace.java

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

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

/**An external function for creating equaly spaced vectors*/
public class linspace extends ExternalFunction
{
	public OperandToken evaluate(Token[] operands)
	{

        if (getNArgIn(operands) != 3)
   			throwMathLibException("linspace: number of arguments != 3");

		if (   (!(operands[0] instanceof DoubleNumberToken))
			|| (!(operands[1] instanceof DoubleNumberToken))
		    || (!(operands[2] instanceof DoubleNumberToken)) ) 
   			throwMathLibException("linspace: wrong type of arguments");


		// get data from arguments
		double x1 =      ((DoubleNumberToken)operands[0]).getReValues()[0][0];
		double x2 =      ((DoubleNumberToken)operands[1]).getReValues()[0][0];		
		int    n  = (int)((DoubleNumberToken)operands[2]).getReValues()[0][0];

		double[][] values = new double[1][n];
		double     dx     = (x2-x1) / (double)(n-1);
		for (int i=0; i<n ; i++)
		{
			values[0][i] = x1 +  ((double)i) * dx;
		}
		
		return new DoubleNumberToken(values);		
	}
}

/*
@GROUP
general
@SYNTAX
matrix = linspace(start, end, no of values)
@DOC
Returns a matrix going from start to end with count elements.
@EXAMPLES
<programlisting>
linspace(0, 1, 11) = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1] 
linspace(0, 10 , 3) = [0, 5, 10]
</programlisting>
@NOTES
A similar result can be obtained by using the colon operator.
@SEE
*/

⌨️ 快捷键说明

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