import static java.lang.System.out;
import javastat.algorithm.*;
import javastat.util.*;
/**
*
* Example: class NewtonRaphsonAlgorithm.
* Object equations:
* 7x^3-10x-y-1=0
* 8y^3-11y+x-1=0
*/
public class NewtonRaphsonAlgorithmExample extends
NewtonRaphsonAlgorithm
{
public
NewtonRaphsonAlgorithmExample(){}
public
double[] objectFunctionVector(double[] s)
{
return new double[]{
7 * Math.pow(s[0],
3.0) - 10 * s[0] - s[1] - 1.0,
8 * Math.pow(s[1],
3.0) - 11 * s[1] + s[0] - 1.0};
}
public
double[][] firstDerivativeMatrix(double[] s)
{
return new double[][]{
{21 * Math.pow(s[0],
2.0) - 10.0, -1.0},
{1.0, 24 * Math.pow(s[1],
2.0) - 11.0}};
}
public
static void main(String arg[])
{
NewtonRaphsonAlgorithmExample example =
new NewtonRaphsonAlgorithmExample();
double[][] start = {{1.0, 0.0}, {1.0, 1.0}, {1.0, -1.0}};
double[] solution1 = example.getSolution(start[0]);
double[] solution2 = example.getSolution(start[1]);
double[] solution3 = example.getSolution(start[2]);
}
}
Results:
Solution:
1.24339 0.02213
Solution:
1.29129 1.15913
Solution:
1.18608 -1.18097