/* ** Lesson 6.2: Two-Variable Scalar-Valued Function ** g(x) = (x[1]^2+x[2]-11)^2 + (x[1]+x[2]^2-7)^2 */ use gpe2; output file=gpe\output6.2 reset; fn g(data,x)=(x[1]^2+x[2]-11)^2+(x[1]+x[2]^2-7)^2; call reset; _nlopt=0; _method=1; _iter=100; _step=1; _conv=1; _b={3,-2}; call estimate(&g,0); /* _deriv=&g1|&g2; call estimate(&g,0); */ end; proc g1(data,x); @ 1st derivative of g(x) @ local f1,f2; f1=4*x[1]*(x[1]^2+x[2]-11)+2*(x[1]+x[2]^2-7); f2=2*(x[1]^2+x[2]-11)+4*x[2]*(x[1]+x[2]^2-7); retp (f1~f2); endp; proc g2(data,x); @ 2nd derivative of g(x) @ local f11,f22,f12; f11=12*x[1]^2+4*x[2]-42; f22=4*x[1]+12*x[2]^2-26; f12=4*(x[1]+x[2]); retp ((f11~f12)|(f12~f22)); endp;