
function diff = BGcomp(params,T,R)
% This function is called by LSQNONLIN.
% params is a vector which contains the coefficients of the
% equation. t and r are the option data sets that were
% passed to lsqnonlin.
 

Z=params(2)./T;
FJ51=120*zeta(5)-exp(-1.0.*Z).*(Z.^5+5*Z.^4+20*Z.^3+60*Z.^2+120.*Z+120);
FJ52=-exp(-2.0.*Z).*(Z.^5+5*Z.^4/2+20*Z.^3/4+60*Z.^2/8+120.*Z/16+120/32);
FJ53=-exp(-3.0.*Z).*(Z.^5+5*Z.^4/3+20*Z.^3/9+60*Z.^2/27+120.*Z/81+120/243);
FJ54=-exp(-4.0.*Z).*(Z.^5+5*Z.^4/4+20*Z.^3/16+60*Z.^2/64+120.*Z/256+120/1024);
FJ55=-exp(-5.0.*Z).*(Z.^5+5*Z.^4/5+20*Z.^3/25+60*Z.^2/125+120.*Z/625+120/3125);
FJ56=-exp(-6.0.*Z).*(Z.^5+5*Z.^4/6+20*Z.^3/36+60*Z.^2/216+120.*Z/1296+120/7776);
FJ57=-exp(-7.0.*Z).*(Z.^5+5*Z.^4/7+20*Z.^3/49+60*Z.^2/343+120.*Z/2401+120/16807);
FJ58=-exp(-8.0.*Z).*(Z.^5+5*Z.^4/8+20*Z.^3/64+60*Z.^2/512+120.*Z/4096+120/32768);
FJ59=-exp(-9.0.*Z).*(Z.^5+5*Z.^4/9+20*Z.^3/81+60*Z.^2/729+120.*Z/6561+120/59049);
FJ510=-exp(-10.0.*Z).*(Z.^5+5*Z.^4/10+20*Z.^3/100+60*Z.^2/1000+120.*Z/10000+120/100000);
FBG1=T.^5/(params(2))^6.*FJ51;
FBG2=T.^5/(params(2))^6.*FJ52;
FBG3=T.^5/(params(2))^6.*FJ53;
FBG4=T.^5/(params(2))^6.*FJ54;
FBG5=T.^5/(params(2))^6.*FJ55;
FBG6=T.^5/(params(2))^6.*FJ56;
FBG7=T.^5/(params(2))^6.*FJ57;
FBG8=T.^5/(params(2))^6.*FJ58;
FBG9=T.^5/(params(2))^6.*FJ59;
FBG10=T.^5/(params(2))^6.*FJ510;
FBGT=FBG1+FBG2+FBG3+FBG4+FBG5+FBG6+FBG7+FBG8+FBG9+FBG10;
FY =params(3)+params(1)*(FBGT);
diff = FY - R;
end

