! Given a function of 2 variables, (ChartPcontour.lng)
1) Create Surface and Contour charts of it,
2) Find a global minimum ;
! Keywords: Chart, Graph, ChartPsurface, ChartPcontour, Global;
PROCEDURE bivariatefun:
fval = x*@SIN(y) + y*@SIN(x);
ENDPROCEDURE
SUBMODEL bivariateopt:
min = fxy;
fxy = x*@SIN(y) + y*@SIN(x);
@free( fxy); ! It could be < 0;
@BND( lb, x, ub);
@BND( lb, y, ub);
ENDSUBMODEL
CALC:
lb = -10; ! Lower bound for x & y;
ub = 10; ! Upper bound for x & y;
@CHARTPSURFACE( 'f(x,y)=x*sin(y)+y*sin(x)', ! Chart title;
'X-axis', 'Y-axis', 'z-axis', ! Titles of the axes;
bivariatefun, ! Name of function procedure;
x, lb, ub, ! X variable and bounds;
y, lb, ub, ! Y variable and bounds;
'f(x,y)', fval); ! Output title and variable;
@CHARTPCONTOUR( 'f(x,y)=x*sin(y)+y*sin(x)', ! Chart title;
'X-axis', 'Y-axis', 'z-axis', ! Titles of the axes;
bivariatefun, ! Name of function procedure;
x, lb, ub, ! X variable and bounds;
y, lb, ub, ! Y variable and bounds;
'f(x,y)', fval); ! Output title and variable;
! Optimize it;
@SET( 'GLOBAL',1); ! Use Global solver? 0:No, 1:Yes;
@SOLVE( bivariateopt);
@WRITE(' f(x,y) achieves a global minimum value = ', fxy,
', at x = ',x,', y = ',y, @NEWLINE(1));
ENDCALC
|