在该示例下面的段落中,作者描述了创建
DerivativeStructures的方法。这不是魔术。在您引用的示例中,应该有人编写该函数
f。好吧,这还不是很清楚。
用户可以通过多种方式创建UnivariateDifferentiableFunction接口的实现。第一种方法是直接使用DerivativeStructure的适当方法直接编写它,以计算加法,减法,正弦,余弦…这通常是很简单的,并且无需记住区分规则:用户代码仅表示功能本身,差异将在引擎盖下自动计算。第二种方法是编写经典的UnivariateFunction并将其传递给UnivariateFunctionDifferentiator接口的现有实现,以检索同一函数的差异版本。第一种方法更适合于用户已经控制了所有基础代码的小型功能。
使用第一个想法。
// Function of 1 variable, keep track of 3 derivatives with respect to that variable,// use 2.5 as the current value. Basically, the identity function.DerivativeStructure x = new DerivativeStructure(1, 3, 0, 2.5);// Basically, x --> x^2.DerivativeStructure x2 = x.pow(2);//Linear combination: y = 4x^2 + 2xDerivativeStructure y = new DerivativeStructure(4.0, x2, 2.0, x);System.out.println("y = " + y.getValue());System.out.println("y' = " + y.getPartialDerivative(1));System.out.println("y'' = " + y.getPartialDerivative(2));System.out.println("y''' = " + y.getPartialDerivative(3));


