x = newton('as', [1e-10 5e-10 0 1e-6 0 0]', 1e-10);

Cr     = x(1); %M
AsO4   = x(2); %M 
H3AsO4 = x(3); %M
H      = x(4); %M
H2AsO4 = x(5); %M
HAsO4  = x(6); %M

m_As     = 74.92;          %g/mol
m_AsO4   = m_As+4*15.999;  %g/mol
m_HAsO4  = m_AsO4+1.008;   %g/mol
m_H2AsO4 = m_AsO4+1.008*2; %g/mol
m_H3AsO4 = m_AsO4+1.008*3; %g/mol

%m_As1 = [AsO4*m_AsO4 + HAsO4*m_HAsO4 + H2AsO4*m_H2AsO4 + H3AsO4*m_H3AsO4]; %g/dm3
mtot_As2 = m_As*sum([AsO4 HAsO4 H2AsO4 H3AsO4]);

disp(' ')
disp('"Fri Arsenik"')
disp('   (mol/dm^3)')
disp(AsO4+HAsO4+H2AsO4+H3AsO4)
disp('   (mg/m^3)')
disp(mtot_As2.*1e6)

%iii)
%pH = [5:0.5:7.5];
%c  = [1.2317e-006 3.9624e-007 1.3201e-007 4.7853e-008 2.0052e-008 9.7447e-009]
%ph = linspace(5,7.5,100);
%C  = spline(pH,c,ph);
%plot(ph,C)
%hold on
%plot(pH,c,'+')
%title('Arenikhaltens pH-beroende')
%xlabel('pH')
%ylabel('Fritt As (M)')
%grid