java fastmethod_Java FastMath.cbrt方法代码示例

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类

/** Compute nth root of a derivative structure.

* @param operand array holding the operand

* @param operandOffset offset of the operand in its array

* @param n order of the root

* @param result array where result must be stored (for

* nth root the result array cannot be the input

* array)

* @param resultOffset offset of the result in its array

*/

public void rootN(final double[] operand, final int operandOffset, final int n,

final double[] result, final int resultOffset) {

// create the function value and derivatives

// [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]

double[] function = new double[1 + order];

double xk;

if (n == 2) {

function[0] = FastMath.sqrt(operand[operandOffset]);

xk = 0.5 / function[0];

} else if (n == 3) {

function[0] = FastMath.cbrt(operand[operandOffset]);

xk = 1.0 / (3.0 * function[0] * function[0]);

} else {

function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);

xk = 1.0 / (n * FastMath.pow(function[0], n - 1));

}

final double nReciprocal = 1.0 / n;

final double xReciprocal = 1.0 / operand[operandOffset];

for (int i = 1; i <= order; ++i) {

function[i] = xk;

xk *= xReciprocal * (nReciprocal - i);

}

// apply function composition

compose(operand, operandOffset, function, result, resultOffset);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值