Warning: Trying to access array offset on value of type null in /home/site/wwwroot/lib/plugins/move/action/rename.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at /home/site/wwwroot/lib/plugins/move/action/rename.php:42) in /home/site/wwwroot/inc/actions.php on line 38
linear_interpolation [topas wiki]

User Tools

Site Tools


linear_interpolation

Linear interpolation background functions

A set of linear interpolation background functions, similar to GSAS background function 7 (p130 of GSAS manual), with 6, 12, 24 and 36 parameters. The function splits the pattern into N equal segments with N+1 refined background intensity points with straight lines describing the background between each point. These functions use nested IF loops to significantly decrease the calculation time compared to subsequent IF statements. The macros can be used to draw your own background by fixing the background intensity values at the observed value… e.g. Bkg_LinInterpol_N6(!bk0, 370, !bk1, 309, !bk2, 171, !bk3, 88, !bk4, 72, !bk5, 42, !bk6, 30) …or just used to refine even the most tricky of backgrounds which are not well served by gradually changing mathematical functions. Example of use: Bkg_LinInterpol_N36(bk0, 0, bk1, 500, bk2, 0, bk3, 500, bk4, 0, bk5, 500, bk6, 0, bk7, 500, bk8, 0, bk9, 500, bk10, 0, bk11, 500, bk12, 0, bk13, 500, bk14, 0, bk15, 500, bk16, 0, bk17, 500, bk18, 0, bk19, 500, bk20, 0, bk21, 500, bk22, 0, bk23, 500, bk24, 0, bk25, 500, bk26, 0, bk27, 500, bk28, 0, bk29, 500, bk30, 0, bk31, 500, bk32, 0, bk33, 500, bk34, 0, bk35, 500, bk36, 0)

Linear interpolation background function with 6 parameters

macro Bkg_LinInterpol_N6(bk0, b0v, bk1, b1v, bk2, b2v, bk3, b3v, bk4, b4v, bk5, b5v, bk6, b6v)
{
prm pStep =((X*0)+X2-X1)/6;
prm pStart =((X*0)+X1);
prm Xval0 = pStart;
prm Xval1 = pStart+pStep;
prm Xval2 = pStart+(pStep*2);
prm Xval3 = pStart+(pStep*3);
prm Xval4 = pStart+(pStep*4);
prm Xval5 = pStart+(pStep*5);
 
   prm bk0  b0v
	prm bk1  b1v
   prm bk2  b2v
   prm bk3  b3v
   prm bk4  b4v
   prm bk5  b5v
   prm bk6  b6v
 
fit_obj =
	IF (X < Xval3) THEN
		IF (X < Xval1) THEN
			((bk1-bk0)/pStep)*(X-Xval0)+bk0
		ELSE IF (X < Xval2) THEN
			((bk2-bk1)/pStep)*(X-Xval1)+bk1
		ELSE
			((bk3-bk2)/pStep)*(X-Xval2)+bk2
		ENDIF
		ENDIF
	ELSE IF (X < Xval4) THEN
		((bk4-bk3)/pStep)*(X-Xval3)+bk3
	ELSE IF (X < Xval5) THEN
		((bk5-bk4)/pStep)*(X-Xval4)+bk4
	ELSE
		((bk6-bk5)/pStep)*(X-Xval5)+bk5
ENDIF
ENDIF
ENDIF
;
}

Linear interpolation background function with 12 parameters

macro Bkg_LinInterpol_N12(bk0, b0v, bk1, b1v, bk2, b2v, bk3, b3v, bk4, b4v, bk5, b5v, bk6, b6v, bk7, b7v, bk8, b8v, bk9, b9v, bk10, b10v, bk11, b11v, bk12, b12v)
{
prm pStep =((X*0)+X2-X1)/12;
prm pStart =((X*0)+X1);
prm Xval0 = pStart;              prm Xval6 = pStart+(pStep*6);
prm Xval1 = pStart+pStep;        prm Xval7 = pStart+(pStep*7);
prm Xval2 = pStart+(pStep*2);    prm Xval8 = pStart+(pStep*8);
prm Xval3 = pStart+(pStep*3);    prm Xval9 = pStart+(pStep*9);
prm Xval4 = pStart+(pStep*4);    prm Xval10 = pStart+(pStep*10);
prm Xval5 = pStart+(pStep*5);    prm Xval11 = pStart+(pStep*11);
 
   prm bk0  b0v	prm bk7  b7v
	prm bk1  b1v   prm bk8  b8v
   prm bk2  b2v   prm bk9  b9v
   prm bk3  b3v   prm bk10  b10v
   prm bk4  b4v   prm bk11  b11v
   prm bk5  b5v   prm bk12  b12v
   prm bk6  b6v
 
fit_obj =
		IF (X < Xval6) THEN
				IF (X < Xval3) THEN
						IF (X < Xval1) THEN
							((bk1-bk0)/pStep)*(X-Xval0)+bk0
						ELSE IF (X < Xval2) THEN
							((bk2-bk1)/pStep)*(X-Xval1)+bk1
						ELSE
							((bk3-bk2)/pStep)*(X-Xval2)+bk2
						ENDIF
						ENDIF
				ELSE
						IF (X < Xval4) THEN
							((bk4-bk3)/pStep)*(X-Xval3)+bk3
						ELSE IF (X < Xval5) THEN
							((bk5-bk4)/pStep)*(X-Xval4)+bk4
						ELSE
							((bk6-bk5)/pStep)*(X-Xval5)+bk5
						ENDIF
						ENDIF
				ENDIF
		ELSE
				IF (X < Xval9) THEN
						IF (X < Xval7) THEN
							((bk7-bk6)/pStep)*(X-Xval6)+bk6
						ELSE IF (X < Xval8) THEN
							((bk8-bk7)/pStep)*(X-Xval7)+bk7
						ELSE
							((bk9-bk8)/pStep)*(X-Xval8)+bk8
						ENDIF
						ENDIF
				ELSE
						IF (X < Xval10) THEN
							((bk10-bk9)/pStep)*(X-Xval9)+bk9
						ELSE IF (X < Xval11) THEN
							((bk11-bk10)/pStep)*(X-Xval10)+bk10
						ELSE
							((bk12-bk11)/pStep)*(X-Xval11)+bk11
						ENDIF
						ENDIF
				ENDIF
		ENDIF
;
}

Linear interpolation background function with 24 parameters

macro Bkg_LinInterpol_N24(bk0, b0v, bk1, b1v, bk2, b2v, bk3, b3v, bk4, b4v, bk5, b5v, bk6, b6v, bk7, b7v, bk8, b8v, bk9, b9v, bk10, b10v, bk11, b11v, bk12, b12v, bk13, b13v, bk14, b14v, bk15, b15v, bk16, b16v, bk17, b17v, bk18, b18v, bk19, b19v, bk20, b20v, bk21, b21v, bk22, b22v, bk23, b23v, bk24, b24v)
{
prm pStep =((X*0)+X2-X1)/24;
prm pStart =((X*0)+X1);
prm Xval0 = pStart;                prm Xval12 = pStart+(pStep*12);
prm Xval1 = pStart+pStep;          prm Xval13 = pStart+(pStep*13);
prm Xval2 = pStart+(pStep*2);      prm Xval14 = pStart+(pStep*14);
prm Xval3 = pStart+(pStep*3);      prm Xval15 = pStart+(pStep*15);
prm Xval4 = pStart+(pStep*4);      prm Xval16 = pStart+(pStep*16);
prm Xval5 = pStart+(pStep*5);      prm Xval17 = pStart+(pStep*17);
prm Xval6 = pStart+(pStep*6);      prm Xval18 = pStart+(pStep*18);
prm Xval7 = pStart+(pStep*7);      prm Xval19 = pStart+(pStep*19);
prm Xval8 = pStart+(pStep*8);      prm Xval20 = pStart+(pStep*20);
prm Xval9 = pStart+(pStep*9);      prm Xval21 = pStart+(pStep*21);
prm Xval10 = pStart+(pStep*10);    prm Xval22 = pStart+(pStep*22);
prm Xval11 = pStart+(pStep*11);    prm Xval23 = pStart+(pStep*23); 
 
   prm bk0  b0v   prm bk10  b10v  prm bk20  b20v
	prm bk1  b1v   prm bk11  b11v  prm bk21  b21v
   prm bk2  b2v   prm bk12  b12v  prm bk22  b22v
   prm bk3  b3v   prm bk13  b13v  prm bk23  b23v
   prm bk4  b4v   prm bk14  b14v  prm bk24  b24v
   prm bk5  b5v   prm bk15  b15v  
   prm bk6  b6v   prm bk16  b16v  
	prm bk7  b7v   prm bk17  b17v  
   prm bk8  b8v   prm bk18  b18v  
   prm bk9  b9v   prm bk19  b19v  
 
fit_obj =
	IF (X < Xval12) THEN
			IF (X < Xval6) THEN
					IF (X < Xval3) THEN
							IF (X < Xval1) THEN
								((bk1-bk0)/pStep)*(X-Xval0)+bk0
							ELSE IF (X < Xval2) THEN
								((bk2-bk1)/pStep)*(X-Xval1)+bk1
							ELSE
								((bk3-bk2)/pStep)*(X-Xval2)+bk2
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval4) THEN
								((bk4-bk3)/pStep)*(X-Xval3)+bk3
							ELSE IF (X < Xval5) THEN
								((bk5-bk4)/pStep)*(X-Xval4)+bk4
							ELSE
								((bk6-bk5)/pStep)*(X-Xval5)+bk5
							ENDIF
							ENDIF
					ENDIF
			ELSE
					IF (X < Xval9) THEN
							IF (X < Xval7) THEN
								((bk7-bk6)/pStep)*(X-Xval6)+bk6
							ELSE IF (X < Xval8) THEN
								((bk8-bk7)/pStep)*(X-Xval7)+bk7
							ELSE
								((bk9-bk8)/pStep)*(X-Xval8)+bk8
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval10) THEN
								((bk10-bk9)/pStep)*(X-Xval9)+bk9
							ELSE IF (X < Xval11) THEN
								((bk11-bk10)/pStep)*(X-Xval10)+bk10
							ELSE
								((bk12-bk11)/pStep)*(X-Xval11)+bk11
							ENDIF
							ENDIF
					ENDIF
			ENDIF
	ELSE
			IF (X < Xval18) THEN
					IF (X < Xval15) THEN
							IF (X < Xval13) THEN
								((bk13-bk12)/pStep)*(X-Xval12)+bk12
							ELSE IF (X < Xval14) THEN
								((bk14-bk13)/pStep)*(X-Xval13)+bk13
							ELSE
								((bk15-bk14)/pStep)*(X-Xval14)+bk14
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval16) THEN
								((bk16-bk15)/pStep)*(X-Xval15)+bk15
							ELSE IF (X < Xval17) THEN
								((bk17-bk16)/pStep)*(X-Xval16)+bk16
							ELSE
								((bk18-bk17)/pStep)*(X-Xval17)+bk17
							ENDIF
							ENDIF
					ENDIF
			ELSE
					IF (X < Xval21) THEN
							IF (X < Xval19) THEN
								((bk19-bk18)/pStep)*(X-Xval18)+bk18
							ELSE IF (X < Xval20) THEN
								((bk20-bk19)/pStep)*(X-Xval19)+bk19
							ELSE
								((bk21-bk20)/pStep)*(X-Xval20)+bk20
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval22) THEN
								((bk22-bk21)/pStep)*(X-Xval21)+bk21
							ELSE IF (X < Xval23) THEN
								((bk23-bk22)/pStep)*(X-Xval22)+bk22
							ELSE
								((bk24-bk23)/pStep)*(X-Xval23)+bk23
							ENDIF
							ENDIF
					ENDIF
			ENDIF
	ENDIF
;
}

Linear interpolation background function with 36 parameters

macro Bkg_LinInterpol_N36(bk0, b0v, bk1, b1v, bk2, b2v, bk3, b3v, bk4, b4v, bk5, b5v, bk6, b6v, bk7, b7v, bk8, b8v, bk9, b9v, bk10, b10v, bk11, b11v, bk12, b12v, bk13, b13v, bk14, b14v, bk15, b15v, bk16, b16v, bk17, b17v, bk18, b18v, bk19, b19v, bk20, b20v, bk21, b21v, bk22, b22v, bk23, b23v, bk24, b24v, bk25, b25v, bk26, b26v, bk27, b27v, bk28, b28v, bk29, b29v, bk30, b30v, bk31, b31v, bk32, b32v, bk33, b33v, bk34, b34v, bk35, b35v, bk36, b36v)
{
prm pStep =((X*0)+X2-X1)/36;
prm pStart =((X*0)+X1);
prm Xval0 = pStart;               prm Xval12 = pStart+(pStep*12);    prm Xval24 = pStart+(pStep*24);
prm Xval1 = pStart+pStep;         prm Xval13 = pStart+(pStep*13);    prm Xval25 = pStart+(pStep*25);
prm Xval2 = pStart+(pStep*2);     prm Xval14 = pStart+(pStep*14);    prm Xval26 = pStart+(pStep*26);
prm Xval3 = pStart+(pStep*3);     prm Xval15 = pStart+(pStep*15);    prm Xval27 = pStart+(pStep*27);
prm Xval4 = pStart+(pStep*4);     prm Xval16 = pStart+(pStep*16);    prm Xval28 = pStart+(pStep*28);
prm Xval5 = pStart+(pStep*5);     prm Xval17 = pStart+(pStep*17);    prm Xval29 = pStart+(pStep*29);
prm Xval6 = pStart+(pStep*6);     prm Xval18 = pStart+(pStep*18);    prm Xval30 = pStart+(pStep*30);
prm Xval7 = pStart+(pStep*7);     prm Xval19 = pStart+(pStep*19);    prm Xval31 = pStart+(pStep*31);
prm Xval8 = pStart+(pStep*8);     prm Xval20 = pStart+(pStep*20);    prm Xval32 = pStart+(pStep*32);
prm Xval9 = pStart+(pStep*9);     prm Xval21 = pStart+(pStep*21);    prm Xval33 = pStart+(pStep*33);
prm Xval10 = pStart+(pStep*10);   prm Xval22 = pStart+(pStep*22);    prm Xval34 = pStart+(pStep*34);
prm Xval11 = pStart+(pStep*11);   prm Xval23 = pStart+(pStep*23);    prm Xval35 = pStart+(pStep*35);
 
   prm bk0  b0v	prm bk10  b10v	  prm bk20  b20v   prm bk30  b30v
	prm bk1  b1v	prm bk11  b11v	  prm bk21  b21v   prm bk31  b31v
   prm bk2  b2v	prm bk12  b12v	  prm bk22  b22v   prm bk32  b32v
   prm bk3  b3v	prm bk13  b13v	  prm bk23  b23v   prm bk33  b33v
   prm bk4  b4v	prm bk14  b14v	  prm bk24  b24v   prm bk34  b34v
   prm bk5  b5v	prm bk15  b15v	  prm bk25  b25v   prm bk35  b35v
   prm bk6  b6v	prm bk16  b16v	  prm bk26  b26v   prm bk36  b36v
	prm bk7  b7v	prm bk17  b17v	  prm bk27  b27v
   prm bk8  b8v	prm bk18  b18v	  prm bk28  b28v
   prm bk9  b9v	prm bk19  b19v	  prm bk29  b29v
 
fit_obj =
	IF (X < Xval12) THEN
			IF (X < Xval6) THEN
					IF (X < Xval3) THEN
							IF (X < Xval1) THEN
								((bk1-bk0)/pStep)*(X-Xval0)+bk0
							ELSE IF (X < Xval2) THEN
								((bk2-bk1)/pStep)*(X-Xval1)+bk1
							ELSE
								((bk3-bk2)/pStep)*(X-Xval2)+bk2
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval4) THEN
								((bk4-bk3)/pStep)*(X-Xval3)+bk3
							ELSE IF (X < Xval5) THEN
								((bk5-bk4)/pStep)*(X-Xval4)+bk4
							ELSE
								((bk6-bk5)/pStep)*(X-Xval5)+bk5
							ENDIF
							ENDIF
					ENDIF
			ELSE
					IF (X < Xval9) THEN
							IF (X < Xval7) THEN
								((bk7-bk6)/pStep)*(X-Xval6)+bk6
							ELSE IF (X < Xval8) THEN
								((bk8-bk7)/pStep)*(X-Xval7)+bk7
							ELSE
								((bk9-bk8)/pStep)*(X-Xval8)+bk8
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval10) THEN
								((bk10-bk9)/pStep)*(X-Xval9)+bk9
							ELSE IF (X < Xval11) THEN
								((bk11-bk10)/pStep)*(X-Xval10)+bk10
							ELSE
								((bk12-bk11)/pStep)*(X-Xval11)+bk11
							ENDIF
							ENDIF
					ENDIF
			ENDIF
	ELSE IF (X < Xval24) THEN
			IF (X < Xval18) THEN
					IF (X < Xval15) THEN
							IF (X < Xval13) THEN
								((bk13-bk12)/pStep)*(X-Xval12)+bk12
							ELSE IF (X < Xval14) THEN
								((bk14-bk13)/pStep)*(X-Xval13)+bk13
							ELSE
								((bk15-bk14)/pStep)*(X-Xval14)+bk14
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval16) THEN
								((bk16-bk15)/pStep)*(X-Xval15)+bk15
							ELSE IF (X < Xval17) THEN
								((bk17-bk16)/pStep)*(X-Xval16)+bk16
							ELSE
								((bk18-bk17)/pStep)*(X-Xval17)+bk17
							ENDIF
							ENDIF
					ENDIF
			ELSE
					IF (X < Xval21) THEN
							IF (X < Xval19) THEN
								((bk19-bk18)/pStep)*(X-Xval18)+bk18
							ELSE IF (X < Xval20) THEN
								((bk20-bk19)/pStep)*(X-Xval19)+bk19
							ELSE
								((bk21-bk20)/pStep)*(X-Xval20)+bk20
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval22) THEN
								((bk22-bk21)/pStep)*(X-Xval21)+bk21
							ELSE IF (X < Xval23) THEN
								((bk23-bk22)/pStep)*(X-Xval22)+bk22
							ELSE
								((bk24-bk23)/pStep)*(X-Xval23)+bk23
							ENDIF
							ENDIF
					ENDIF
			ENDIF
	ELSE 
			IF (X < Xval30) THEN
					IF (X < Xval27) THEN
							IF (X < Xval25) THEN
								((bk25-bk24)/pStep)*(X-Xval24)+bk24
							ELSE IF (X < Xval26) THEN
								((bk26-bk25)/pStep)*(X-Xval25)+bk25
							ELSE
								((bk27-bk26)/pStep)*(X-Xval26)+bk26
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval28) THEN
								((bk28-bk27)/pStep)*(X-Xval27)+bk27
							ELSE IF (X < Xval29) THEN
								((bk29-bk28)/pStep)*(X-Xval28)+bk28
							ELSE
								((bk30-bk29)/pStep)*(X-Xval29)+bk29
							ENDIF
							ENDIF
					ENDIF
			ELSE
					IF (X < Xval33) THEN
							IF (X < Xval31) THEN
								((bk31-bk30)/pStep)*(X-Xval30)+bk30
							ELSE IF (X < Xval32) THEN
								((bk32-bk31)/pStep)*(X-Xval31)+bk31
							ELSE
								((bk33-bk32)/pStep)*(X-Xval32)+bk32
							ENDIF
							ENDIF
					ELSE
							IF (X < Xval34) THEN
								((bk34-bk33)/pStep)*(X-Xval33)+bk33
							ELSE IF (X < Xval35) THEN
								((bk35-bk34)/pStep)*(X-Xval34)+bk34
							ELSE
								((bk36-bk35)/pStep)*(X-Xval35)+bk35
							ENDIF
							ENDIF
					ENDIF
			ENDIF
	ENDIF
	ENDIF
;
}
linear_interpolation.txt · Last modified: 2022/11/03 15:08 by 127.0.0.1