function cost = RB03_cost(XX);
%XX;
%nX=length(XX);
global rrs_obs wave

    [aw,bbw]=water_iops_PF_TScorr(wave,15,33);
    aph=phyto_avg_abs(wave);

chl = XX(1); acdom = XX(2); anap = XX(3); cp = XX(4); bbpratio = XX(5); gamma = XX(6) 
Scdom = 0.018; Snap = 0.011; 

atotal  = aw + aph.*chl + acdom.*exp(-Scdom*(wave-(443*ones(size(wave))))) + anap.*exp(-Snap*(wave-(443*ones(size(wave)))));%aw+af+ag+an
bbtotal = bbw + bbpratio.* (cp.*(wave./(443*ones(size(wave)))) -  (aph.*chl + anap.*exp(-Snap*(wave-(443*ones(size(wave))))))).^gamma;%bbw + bbratio*(cp-ap)^gamma

g1 = 0.0949; g2 = 0.0794; 

x = bbtotal ./ (atotal + bbtotal);
    
rrs = g1 .*x + g2 .* x .* x;

cost = sum((rrs-rrs_obs).^2);
