#include <oxstd.h>
#import <maximize>


fRosenbrock(const vP, const adFunc, const avScore, const amHessian)
{
    adFunc[0] = -100 * (vP[1][0] - vP[0][0] ^ 2) ^ 2
        - (1 - vP[0][0]) ^ 2;            // function value

    if (avScore)                   // if !0: compute score
    {  // this bit is not needed for numerical derivatives
        (avScore[0])[0][0] = 400 * (vP[1][0] - vP[0][0] ^ 2)
             * vP[0][0] + 2 * (1 - vP[0][0]);
        (avScore[0])[1][0] =-200 * (vP[1][0] - vP[0][0] ^ 2);
    }
return 1;
}

main()
{
    decl vp, dfunc, vscore, mhess;

    vscore = vp = zeros(2, 1);          // starting values

    fRosenbrock(vp, &dfunc, &vscore, 0);
    print("analytical first derivative at <0;0>", vscore);

    if (Num1Derivative(fRosenbrock, vp, &vscore))
        print("numerical 1st derivative at <0;0>", vscore);

    if (Num2Derivative(fRosenbrock, vp, &mhess))
        print("numerical 2nd derivative at <0;0>", mhess);
}

