MCPcopy Create free account
hub / github.com/PX4/eigen / fcn_chkder

Function fcn_chkder

unsupported/test/NonLinearOptimization.cpp:18–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#define LM_EVAL_COUNT_TOL 4/3
17
18int fcn_chkder(const VectorXd &x, VectorXd &fvec, MatrixXd &fjac, int iflag)
19{
20 /* subroutine fcn for chkder example. */
21
22 int i;
23 assert(15 == fvec.size());
24 assert(3 == x.size());
25 double tmp1, tmp2, tmp3, tmp4;
26 static const double y[15]={1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1,
27 3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39};
28
29
30 if (iflag == 0)
31 return 0;
32
33 if (iflag != 2)
34 for (i=0; i<15; i++) {
35 tmp1 = i+1;
36 tmp2 = 16-i-1;
37 tmp3 = tmp1;
38 if (i >= 8) tmp3 = tmp2;
39 fvec[i] = y[i] - (x[0] + tmp1/(x[1]*tmp2 + x[2]*tmp3));
40 }
41 else {
42 for (i = 0; i < 15; i++) {
43 tmp1 = i+1;
44 tmp2 = 16-i-1;
45
46 /* error introduced into next statement for illustration. */
47 /* corrected statement should read tmp3 = tmp1 . */
48
49 tmp3 = tmp2;
50 if (i >= 8) tmp3 = tmp2;
51 tmp4 = (x[1]*tmp2 + x[2]*tmp3); tmp4=tmp4*tmp4;
52 fjac(i,0) = -1.;
53 fjac(i,1) = tmp1*tmp2/tmp4;
54 fjac(i,2) = tmp1*tmp3/tmp4;
55 }
56 }
57 return 0;
58}
59
60
61void testChkder()

Callers 1

testChkderFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected