Example of envelop, sew, smooth and resize.
MGL code:
subplot 2 2 0 '':title 'Envelop sample':new d1 1000 'exp(-8*x^2)*sin(10*pi*x)' axis:plot d1 'b':envelop d1 'x':plot d1 'r' subplot 2 2 1 '':title 'Smooth sample':ranges 0 1 0 1 new y0 30 '0.4*sin(pi*x) + 0.3*cos(1.5*pi*x) - 0.4*sin(2*pi*x)+0.5*rnd' copy y1 y0:smooth y1 'x3':plot y1 'r';legend '"3" style' copy y2 y0:smooth y2 'x5':plot y2 'g';legend '"5" style' copy y3 y0:smooth y3 'x':plot y3 'b';legend 'default' plot y0 '{m7}:s';legend 'none' legend:box subplot 2 2 2:title 'Sew sample':rotate 50 60:light on:alpha on new d2 100 100 'mod((y^2-(1-x)^2)/2,0.1)' box:surf d2 'b':sew d2 'xy' 0.1:surf d2 'r' subplot 2 2 3:title 'Resize sample (interpolation)' new x0 10 'rnd':new v0 10 'rnd' resize x1 x0 100:resize v1 v0 100 plot x0 v0 'b+ ':plot x1 v1 'r-':label x0 v0 '%n'
C++ code:
void smgl_dat_extra(mglGraph *gr) // differentiate { gr->SubPlot(2,2,0,""); gr->Title("Envelop sample"); mglData d1(1000); gr->Fill(d1,"exp(-8*x^2)*sin(10*pi*x)"); gr->Axis(); gr->Plot(d1, "b"); d1.Envelop('x'); gr->Plot(d1, "r"); gr->SubPlot(2,2,1,""); gr->Title("Smooth sample"); mglData y0(30),y1,y2,y3; gr->SetRanges(0,1,0,1); gr->Fill(y0, "0.4*sin(pi*x) + 0.3*cos(1.5*pi*x) - 0.4*sin(2*pi*x)+0.5*rnd"); y1=y0; y1.Smooth("x3"); y2=y0; y2.Smooth("x5"); y3=y0; y3.Smooth("x"); gr->Plot(y0,"{m7}:s", "legend 'none'"); //gr->AddLegend("none","k"); gr->Plot(y1,"r", "legend ''3' style'"); gr->Plot(y2,"g", "legend ''5' style'"); gr->Plot(y3,"b", "legend 'default'"); gr->Legend(); gr->Box(); gr->SubPlot(2,2,2); gr->Title("Sew sample"); mglData d2(100, 100); gr->Fill(d2, "mod((y^2-(1-x)^2)/2,0.1)"); gr->Rotate(50, 60); gr->Light(true); gr->Alpha(true); gr->Box(); gr->Surf(d2, "b"); d2.Sew("xy", 0.1); gr->Surf(d2, "r"); gr->SubPlot(2,2,3); gr->Title("Resize sample (interpolation)"); mglData x0(10), v0(10), x1, v1; gr->Fill(x0,"rnd"); gr->Fill(v0,"rnd"); x1 = x0.Resize(100); v1 = v0.Resize(100); gr->Plot(x0,v0,"b+ "); gr->Plot(x1,v1,"r-"); gr->Label(x0,v0,"%n"); }