I've been trying to reproduce Figure 2 from this research paper (full text available).
The Problem
However I can't seem to get the same values as in the paper. I did the math both by hand and with MATLAB, but neither matched their results. I have the approximate solution (as it's from a graph) but after entering all the data and checking multiple times I still haven't been able to find what is wrong. The source for the graph/equation is the article at this link: The chemistry of co-injected BOE. The graph I want to reproduce is their Figure 2:
Above the figure it says: "distribution of the different species in a solution using $1800\,\mathrm{cc}$ of DI water, $100\,\mathrm{cc}$ of $49\%$ w/w HF and $0$ to $200\,\mathrm{cc}$ of $28\%$ w/w $\ce{NH4OH}$."
Here are the results I get for $10\,\mathrm{cc}$, $40\,\mathrm{cc}$ and $90\,\mathrm{cc}$:
$$ \begin{array}{c|cccc} \hline \text{Volume (cc)} & \ce{HF} & \ce{H2F2} & \ce{F-} & \ce{HF2-} \\ \hline 10 & 43\% & 48\% & 3\% & 6\% \\ 40 & 35\% & 33\% & 14\% & 18\% \\ 90 & 21\% & 12\% & 37\% & 30\% \\ \hline \end{array} $$
To calculate the fractions, I'm summing $\ce{HF}$, $\ce{H2F2}$, $\ce{F-}$ and $\ce{HF2-}$ to get the total and then I divide each of them by the total (both concentration and moles should both be valid).
I was wondering if anyone might have an idea of what I might be doing wrong. Or if the graph in the paper might possibly have an error or if there's some other numeric error in the paper.
Originally, I thought something was wrong with MATLAB's solution but I've checked that so many times by now, in more than just the two ways I show down below, that I really feel that that's not the issue. I've been at this problem for a month now, and about a week into it (3 weeks ago) I asked for help with the MATLAB side of things (see post on SO of original problem; I had some friends help out in the end). Honestly I just really want to know what the problem/mistake is.
The Equations
The equations being used from the article are in the image below:
Matlab scripts used
The matlab scripts I used are the following:
First mols.m as a depency of the other two,
%%%% amount of mol, Vol=volume, d=density, pwt=%weight, M=molecularweight
function mol=mols(Vol, d, pwt, M)
mol=(Vol*d*pwt)/M;
end
First script, all matlab calculated
clc;
clear all;
%Units to be used
%Volume is in CC also cm^3, 1 litre is 1000 CC, 1 cc = 1 ml
%density is in g/cm^3
%weigth percentages are in fractions of 0 to 1
%Molecular weight is in g/mol
% pts=10; %number of points for linear spacing
%weight percentages of NH4OH and HF
xhf=0.49;
xnh3=0.28;
%H2O
Vh2o=1800;
dh2o=1.00; %0.997 at 25C when rounded 1
mh2o=18.02;
%HF values
Vhf=100;
dhf49=1.15;
dhf=dh2o+(dhf49-dh2o)*xhf/0.49; %@ 25C
Mhf=20.01;
nhf=mols(Vhf,dhf,xhf,Mhf);
%NH4OH (NH3) values
% Vnh3=linspace(0.1*Vhf,1.9*Vhf,pts);
Vnh3=10;
dnh3=0.9; %for ~20-31% @~20-25C
Mnh3=17.03; %The wt% of NH4OH actually refers to the wt% of NH3 dissolved in H2O
nnh3=mols(Vnh3,dnh3,xnh3,Mnh3);
if max(nnh3)>=nhf
error(['There are more mols NH4OH,',num2str(max(nnh3)),', than mols HF,',num2str(nhf),'.'])
end
%% Calculations for species
Vt=(Vhf+Vh2o+Vnh3)/1000; %litre
A=nhf/Vt; %mol/l
B=nnh3/Vt; %mol/l
syms HF F H2F2 HF2 NH3 NH4 H OH
eq2= H*F/HF==6.85*10^(-4);
eq3= NH3*H/NH4==6.31*10^(-10);
eq4= H*OH==10^(-14);
eq5= HF2/(HF*F)==3.963;
eq6= H2F2/(HF^2)==2.7;
eq7= H+NH4==OH+F+HF2;
eq8= HF+F+2*H2F2+2*HF2==A;
eq9= NH3+NH4==B;
eqns=[eq2,eq5,eq6,eq8,eq4,eq3,eq9,eq7];
varias=[HF, F, H2F2, HF2, NH3, NH4, H, OH];
assume(HF> 0 & F>= 0 & H2F2>= 0 & HF2>= 0& NH3>= 0 & NH4>= 0 & H>= 0 & OH>= 0)
[HF, F, H2F2, HF2, NH3, NH4, H, OH]=vpasolve(eqns,varias);% [0 max([A,B])])
totalHF=double(HF)+double(F)+double(H2F2)+double(HF2);
HFf=double(HF)/totalHF %fraction of species for HF
H2F2f=double(H2F2)/totalHF %fraction of species for H2F2
Ff=double(F)/totalHF %fraction of species for F-
HF2f=double(HF2)/totalHF %fraction of species for HF2-
Second script, equation were written out and solved by hand until being left with the final equation which was then solved in matlab
clc;
close all;
clear all;
%Units to be used
%Volume is in CC also cm^3, 1 litre is 1000 CC, 1 cc = 1 ml
%density is in g/cm^3
%weigth percentages are in fractions of 0 to 1
%Molecular weight is in g/mol
% pts=10; %number of points for linear spacing
%weight percentages of NH4OH and HF
xhf=0.49;
xnh3=0.28;
%H2O
Vh2o=1800;
dh2o=1.00; %0.997 at 25C when rounded 1
mh2o=18.02;
%HF values
Vhf=100;
dhf49=1.15;
dhf=dh2o+(dhf49-dh2o)*xhf/0.49; %@ 25C
Mhf=20.01;
nhf=mols(Vhf,dhf,xhf,Mhf);
%NH4OH (NH3) values
% Vnh3=linspace(0.1*Vhf,1.9*Vhf,pts);
Vnh3=10;
dnh3=0.9; %for ~20-31% @~20-25C
Mnh3=17.03; %The wt% of NH4OH actually refers to the wt% of NH3 dissolved in H2O
nnh3=mols(Vnh3,dnh3,xnh3,Mnh3);
if max(nnh3)>=nhf
error(['There are more mols NH4OH,',num2str(max(nnh3)),', than mols HF,',num2str(nhf),'.'])
end
n2=nnh3;
n3=nhf-nnh3;
%% Calculations for species
Vt=(Vhf+Vh2o+Vnh3)/1000; %litre
A=nhf/Vt; %mol/l
B=nnh3/Vt; %mol/l
syms H
yl=H*(1+B/(H+6.31*1e-10));
HF=(sqrt((H+6.85*1e-4)^2+4*A*H*(H*5.4+5.42*1e-3))-(H+6.85*1e-4))/(2*(H*5.4+5.42*1e-3));
yr1=(1/H)*(1e-14+6.85*1e-4*HF*(1+3.963*HF));
hf=matlabFunction(yr1-yl);
H3O=fzero(hf, 6.23e-3)
yval=double(subs(yl,H,H3O))
yvalcheck=double(subs(yr1,H,H3O))
figure
hold on
bnds=[H3O-0.1 H3O+0.1 yval-0.1 yval+0.1];
ezplot(yl,bnds);
ezplot(yr1,bnds);
plot(H3O,yval,'or','MarkerSize',10,'LineWidth',2)
HF=double(subs(HF,H,H3O));
F=6.85*1e-4*HF/H3O;
HF2=3.963*HF*F;
H2F2=2.7*HF^2;
totalHF=HF+F+H2F2+HF2;
HFf=HF/totalHF %fraction of species for HF
H2F2f=H2F2/totalHF %fraction of species for H2F2
Ff=F/totalHF %fraction of species for F-
HF2f=HF2/totalHF %fraction of species for HF2-