11.81 Sample ‘minmax

Function minmax get position of local minimums and maximums.

MGL code:

define $p 30
new h 300 300 '-sqrt(1-x^2-y^2)*(3*x*y^2*$p-x^3*$p+6*y)/(3*sqrt(2))+x*y+(y^2+x^2)*$p/3 -7*(y^2+x^2)^2*$p/24+y^2+3*x^2'

minmax e h
subplot 1 1 0 '':title 'MinMax sample'
crange h:dens h:box
fplot 'sin(2*pi*t)' 'cos(2*pi*t)' '0' 'k'
plot e(0)*2-1 e(1)*2-1 '. c'

C++ code:

void smgl_minmax(mglGraph *gr)	// test minmax
{
	mglData h(300,300);
	gr->Fill(h,"-sqrt(1-x^2-y^2)*(3*x*y^2*30-x^3*30+6*y)/(3*sqrt(2))+x*y+(y^2+x^2)*10 -7*(y^2+x^2)^2*30/24+y^2+3*x^2");
	mglData e=h.MinMax();
	if(big!=3)	{	gr->SubPlot(1,1,0,"");	gr->Title("MinMax sample");	}
	gr->SetRange('c',h);	gr->Dens(h);	gr->Box();
	gr->FPlot("sin(2*pi*t)","cos(2*pi*t)","0","k");
	e*=2;	e-=1;
	gr->Plot(e(0),e(1),". c");
}

Sample minmax