11.99 Sample ‘pulse

Example of pulse parameter determining.

MGL code:

subplot 1 1 0 '<_':title 'Pulse sample'
new a 100 'exp(-6*x^2)':ranges 0 a.nx-1 0 1
axis:plot a

pulse b a 'x'

define m a.max

line b(1) 0 b(1) m 'r='
line b(1)-b(3)/2 0  b(1)-b(3)/2 m 'm|'
line b(1)+b(3)/2 0  b(1)+b(3)/2 m 'm|'
line 0 0.5*m a.nx-1 0.5*m 'h'
new x 100 'x'
plot b(0)*(1-((x-b(1))/b(2))^2) 'g'

C++ code:

void smgl_pulse(mglGraph *gr)
{
	gr->SubPlot(1,1,0,"<_");
	if(big!=3)	gr->Title("Pulse sample");
	mglData a(100);	gr->Fill(a,"exp(-6*x^2)");
	gr->SetRanges(0, a.nx-1, 0, 1);
	gr->Axis();	gr->Plot(a);
	mglData b(a.Pulse('x'));
	double m = b[0];
	gr->Line(mglPoint(b[1],0), mglPoint(b[1],m),"r=");
	gr->Line(mglPoint(b[1]-b[3]/2,0), mglPoint(b[1]-b[3]/2,m),"m|");
	gr->Line(mglPoint(b[1]+b[3]/2,0), mglPoint(b[1]+b[3]/2,m),"m|");
	gr->Line(mglPoint(0,m/2), mglPoint(a.nx-1,m/2),"h");
	char func[128];	sprintf(func,"%g*(1-((x-%g)/%g)^2)",b[0],b[1],b[2]);
	gr->FPlot(func,"g");
}
Sample pulse