/* ** 2-Variable Scalar-Valued Function ** f: RxR -> R */ proc f(z); @ 2-variable scalar-valued function: @ local x,y; @ f(x,y)=(x^2+y-11)^2+(x+y^2-7)^2 @ x=z[1]; y=z[2]; retp((x^2+y-11)^2+(x+y^2-7)^2); endp; proc f1(z); @ 1st analytic derivative of f(x,y) @ local x,y,fx,fy; @ f1(x,y) is 1x2 @ x=z[1]; y=z[2]; fx=4*x*(x^2+y-11)+2*(x+y^2-7); fy=2*(x^2+y-11)+4*y*(x+y^2-7); retp(fx~fy); endp; proc f2(z); @ 2nd analytic derivative of f(x,y) @ local x,y,fxx,fyy,fxy; @ f2(x,y) is 2x2 @ x=z[1]; y=z[2]; fxx=12*x^2+4*y-42; fyy=4*x+12*y^2-26; fxy=4*(x+y); retp((fxx~fxy)|(fxy~fyy)); endp; v={3,2}; @ function evaluation at point v={3,2} @ print f(v); @ f(3,2) @ print f1(v); @ f1(3,2) @ print f2(v); @ f2(3,2) @ /* Numeric Derivatives */ print gradp(&f,v); @ 1st numeric derivative of f(x,y) @ print hessp(&f,v); @ 2nd numeric derivative of f(x,y) @ @ find 4 minima of f(x,y) at: f1=0 0, f2= positive definite @ @ (3,2), (3.5844,-1.8481), (-3.7793,-3.2832), (-2.8051,3.1313) @ @ there is 1 maximum: (-0.27084,-0.92304) with f=181.62 @ @ saddle points: (0.08668,2.88430), (3.38520,0.07358), (-3.07300,-0.08135) @ /* Using graph to find the minimum: Make sure that your GAUSS is configured correctly with your equipment: monitor and printer in particular. Modify the file PQGRUN.CFG if necessary, according to the instruction in the file. */ library pgraph; @ publication graph library @ graphset; @ reset global variables @ x=seqa(-5,0.125,81)'; @ generate data x @ y=seqa(-5,0.125,81); @ generate data y @ z=(x^2+y-11)^2+(x+y^2-7)^2; @ generate function values z @ xtics(-5,5,1,0); @ scale and set x-axis tick marks @ ytics(-5,5,1,0); @ scale and set y-axis tick marks @ ztics(0,900,50,0); @ scale and set z-axis tick marks @ call surface(x,y,z); @ graph 3-D surface @ ztics(0,900,10,1); @ reset z-axis tick to a smaller step @ @ good for detailed contour plot @ call contour(x,y,z); end;