MeaninBandtN=(UpperBoundN+LowerboundN)/2;% Average size
LogMeaninBandt=log10(MeaninBandtN);
datF=MeaninBandtN;
%% For calculating the start number distribution, can be seed or the second point
dCC_point2=interp1(Time1,dCC,t_CSD(num5));
mseed=num3*10^-6;
W_initial=con3/100;
w_point2=dCC_point2+w_eq;
m_con_point2=(m_sol*(1-W_initial)-m_sol*W_initial*M_H2O/M_lactose)./(1-w_point2-w_point2*M_H2O/M_lactose);% Mass of concentrate, acounting for hydrate (in kg)
ifSeeded==1
mt_point2=mseed
else
mt_point2=(m_sol-m_con_point2)+mseed;% Mass of lactose monohydrate crystals (in kg)
end
%% Creating cummalative distribution rahter then normal CSD (data from laser difraction measurements)
%% Determening the number dsitribution at the each time the CSD was measured
% Determening mass crystallized at each point
dCC_point=interp1(Time1,dCC,t_CSD);
w_point=dCC_point+w_eq;
m_con_point=(m_sol*(1-W_initial)-m_sol*W_initial*M_H2O/M_lactose)./(1-w_point-w_point*M_H2O/M_lactose);% Mass of concentrate, acounting for hydrate (in kg)
mt_point=(m_sol-m_con_point)+mseed;% Mass of lactose monohydrate crystals (in kg)
f=@(theta)findmin(theta,TimeL(1:end),dCCL,N_t_00,A0,W_initial,Fraction_t_int,MeaninBandtN,BandwithN,dCCL_H2O,NewdisFractionend,N_end,Cum_total,vec,vec_CSD,mseed);% Function to calculate the difference between measured and moddeled