function y=f(x)

%---------------------
% Ca     ->   x(1)
% SO4    ->   x(2)
% F      ->   x(3)
% H      ->   x(4)
% HF     ->   x(5)
% HSO4   ->   x(6)
%---------------------

ksp1 = 7.1e-5;
ksp2 = 1.46e-10;
Ka1  = 3.53e-4;
ka2  = 1.2e-2;
pH = 7;

y = zeros(size(x));

y(1) = ksp1-x(1)*x(2);
y(2) = ksp2-x(1)*x(3)*x(3);
y(3) = x(2)-x(1)-(10^-4-x(3)-x(5))/2;
y(4) = Ka1*x(5) - x(4)*x(3);
y(5) = x(4)-10^-pH;
y(6) = ka2*x(6) - x(4)*x(2);