1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.optim.nonlinear.vector.constrained;
18
19 import org.hipparchus.linear.Array2DRowRealMatrix;
20 import org.hipparchus.linear.ArrayRealVector;
21 import org.hipparchus.linear.RealMatrix;
22 import org.hipparchus.linear.RealVector;
23
24 public class HockSchittkowskiFunction71 extends TwiceDifferentiableFunction {
25
26 @Override
27 public int dim() {
28 return 4;
29 }
30
31 @Override
32 public double value(RealVector x) {
33 double x1 = x.getEntry(0);
34 double x2 = x.getEntry(1);
35 double x3 = x.getEntry(2);
36 double x4 = x.getEntry(3);
37
38 return x1*x4*(x1+x2+x3)+x3;
39 }
40
41 @Override
42 public RealVector gradient(RealVector x) {
43 RealVector grad=new ArrayRealVector(x.getDimension());
44 double x1 = x.getEntry(0);
45 double x2 = x.getEntry(1);
46 double x3 = x.getEntry(2);
47 double x4 = x.getEntry(3);
48 grad.setEntry(0,x4*(2.0*x1+x2+x3));
49 grad.setEntry(1,x1*x4);
50 grad.setEntry(2,x1*x4+1.0);
51 grad.setEntry(3,x1*(x1+x2+x3));
52 return grad;
53 }
54
55 @Override
56 public RealMatrix hessian(RealVector x) {
57 double x1 = x.getEntry(0);
58 double x2 = x.getEntry(1);
59 double x3 = x.getEntry(2);
60 double x4 = x.getEntry(3);
61 RealMatrix h=new Array2DRowRealMatrix(x.getDimension(),x.getDimension());
62 h.setEntry(0,0, 2.0*x4);
63 h.setEntry(0,1,x4);
64 h.setEntry(0,2,x4);
65 h.setEntry(0,3, (2*x1+x2+x3));
66
67 h.setEntry(1,0, x4);
68 h.setEntry(1,1, 0);
69 h.setEntry(1,2, 0);
70 h.setEntry(1,3, 0);
71
72 h.setEntry(2,0, x4);
73 h.setEntry(2,1, 0);
74 h.setEntry(2,2, 0);
75 h.setEntry(2,3, x1);
76
77 h.setEntry(3,0, x1+x2+x3);
78 h.setEntry(3,1, x1);
79 h.setEntry(3,2, x1);
80 h.setEntry(3,3, 0);
81
82
83
84 return h;
85 }
86
87 }