// f=sqrt((a*(zin-z0-z_corr))^2 + (r0*(exp(-k))^2)+r0*(1-exp(-k))+ kx*(zin-z0-z_corr)-f_corr {+...aN*(zin-z0-z_corr)^N} - {} are not likely to be ever used
doublef=sqrt+exp_r*(1-exp_mk)+kx*z-f_corr;
doublezp=z;
for(inti=5;i<ar.length;i++){
zp*=z;
zp*=z;
f+=ar[i]*zp;
f+=ar[i]*zp;
}
}
if(deriv==null)returnf;// only value, no derivatives
if(deriv==null)returnf;// only value, no derivatives
double[]df_da=newdouble[this.modelParams.length];// last element - derivative for dz
// derivative for z0 (shift) - ar[0]
// df_da[0]=-1.0/sqrt*ar[1]*ar[1]*z;
df_da[0]=-1.0/sqrt*exp_a*exp_a*z;
zp=1.0;
for(inti=4;i<this.modelParams.length;i++){
df_da[0]-=ar[i]*(i-3)*zp;// ar[i] calculated coefficients for current radius
zp*=z;
}
// derivative for a (related to numeric aperture) - ar[1]
// derivative for a (related to lowest PSF radius) - ar[2]
// derivatives calculation independent of z - move to a separate function that can be called once for channel/sample, stored asnd then applied to multiple z measurements
// f=sqrt((a*(zin-z0-z_corr))^2 + (r0*(exp(-k))^2)+r0*(1-exp(-k))+ kx*(zin-z0-z_corr) -f_corr {+...aN*(zin-z0-z_corr)^N} - {} are not likely to be ever used
double[]df_da=newdouble[this.modelParams.length];// last element - derivative for dz
// derivative for z0 (shift) - ar[0]
df_da[0]=-1.0/sqrt*exp_a2*z;
df_da[0]-=kx;
zp=z;
for(inti=5;i<this.modelParams.length;i++){
df_da[0]-=ar[i]*(i-3)*zp;// ar[i] calculated coefficients for current radius
zp*=z;
}
doubledf_dz_corr=df_da[0];
// double df_df_corr=-1;//, so subtract each of dfcorr_dar* from df_dar*
// derivatives for rest (polynomial) coefficients
// double z=z_in-ar[0]-z_corr;
zp=1.0;
// double sqrt=Math.sqrt(exp_a2*z*z + reff2);
// f=sqrt((a*(zin-z0-z_corr))^2 + (r0*(exp(-k))^2) +r0*(1-exp(-k)) + kx*(zin-z0-z_corr) -f_corr{+...aN*(zin-z0-z_corr)^N} - {} are not likely to be ever used
for(inti=4;i<this.modelParams.length;i++){
// derivative for a (related to numeric aperture) - ar[1]