function obj = findfmmobfmdry (x)

global krw0 krg0 S_wc S_gr nw ng visw visg epdry fmmob fmdry

fmmob=x(1);
fmdry=x(2);

krw0=0.79;
krg0=1.0;
S_wc=0.07;
S_gr=0;
nw=1.96;
ng=2.29;
visw=0.001*1e3; %in cp
visg=0.00002*1e3; %in cp
epdry=500;
 
Sw_t=fminbnd('findSwt',S_wc,1-S_gr);

Fwater_t=0.5+(atan(epdry*(Sw_t-fmdry)))/pi;
krw_t=krw0*((Sw_t-S_wc)/(1-S_gr-S_wc)).^nw;
krg_t=krg0*(1-(Sw_t-S_wc)/(1-S_gr-S_wc)).^ng.*(1./(1+fmmob*Fwater_t));

fg_t=1./(1+krw_t.*visg./(krg_t.*visw));
vis_foam_t=1./(krw_t/visw+krg_t/visg);

fg_t_measured=0.5; % experimental data
vis_foam_t_measured=421; % experimental data
obj=((fg_t-fg_t_measured)/fg_t_measured)^2+((vis_foam_t-vis_foam_t_measured)/vis_foam_t_measured)^2;

%% To find the optimal fmmob and fmdry, run the code
% A=fminsearch('findfmmobfmdry',[10000,0.1])
