#include #include float chifit_ts(float tql,float tq,float tqh); float chifit_ts(float tql,float tq,float tqh){ int i; float qerr=2.2; float tqq[3]; float xn; float step; int ifin,istep; float chi2last,chi2min,chi2; float t; ifin=0; istep=0; chi2min=1.0e12; chi2last=1.0e12; t=0.0; step=50; NEXT: istep=istep+1; if(istep>10000)goto FIN; chi2=0.0; tqq[0]=t*t*t*t*exp(-t/33.25); tqq[1]=(50.+t)*(50.+t)*(50.+t)*(50.+t)*exp((-50.-t)/33.25); tqq[2]=(100+t)*(100+t)*(100+t)*(100+t)*exp((-100.-t)/33.25); xn=(tqq[0]*tql+tqq[1]*tq+tqq[2]*tqh)/(tqq[0]*tqq[0]+tqq[1]*tqq[1]+tqq[2]*tqq[2]); chi2=(tql-xn*tqq[0])*(tql-xn*tqq[0])+(tq-xn*tqq[1])*(tq-xn*tqq[1])+(tqh-xn*tqq[2])*(tqh-xn*tqq[2]); // printf(" xn %f tqq %f %f %f %d %d %d \n",xn,xn*tqq[0],xn*tqq[1],xn*tqq[2],tql,tq,tqh); chi2=chi2/(qerr*qerr); // printf(" t chi2 step %f %f %f \n",t,chi2,step); if(chi2chi2)chi2min=chi2; t=t+step; goto NEXT; } if(step<0.0001){ifin=1;goto FIN;} t=t-2*step; step=step/2.; chi2last=1.0e12; goto NEXT; FIN: // printf(" t %f \n",t); return t; }