function y=arsenik_ekvationer(x)
%------------------------------+---------------------------------------+
%   input:
%
%   x(1) = [Cr]
%   x(2) = [AsO4]
%   x(3) = [H3AsO4]
%   x(4) = [H]
%   x(5) = [H2AsO4]
%   x(5) = [HAsO4]
%
%
%   reaction calculation:
%
%   Ksp = [Cr] * [AsO4]
%
%         [H] * [H2AsO4]
%   Ka1 = --------------
%            [H3AsO4]
%
%         [H] * [HAsO4]
%   Ka2 = -------------
%           [H2AsO4]
%
%         [H] * [AsO4]
%   Ka3 = ------------
%           [HAsO4]
%
%   [Cr] = [AsO4] + [H3AsO4] + [H2AsO4] + [HAsO4]
%
%   [H] = 10^(-pH)
%
%----------------------------------------------------------------------
%   Date created: 2003-12-05
%
%   Author: Henrik Skärnell 
%------------------------------+---------------------------------------+

global pH

Ksp = 1e-20;
Ka1 = 5.62e-3;
Ka2 = 1.70e-7;
Ka3 = 3.95e-12;

y(1,1) = Ksp-x(1)*x(2);
y(2,1) = x(4)*x(5)-Ka1*x(3);
y(3,1) = x(4)*x(6)-Ka2*x(5);
y(4,1) = x(4)*x(2)-Ka3*x(6);
y(5,1) = x(1)-x(2)-x(5)-x(6)-x(3);
y(6,1) = x(4)-10^(-pH);