! Chemical equilibrium problem of Peters, Hayes and (Chmbl1)
! Hieftje. Calculate concentrations of various components
! of phosphoric acid, H3PO4, with a pH of 8 and total 
! phosphate concentration of .10. The equilibrium equations
! in obvious form have the following poorly scaled form:

!   H2P * H/ H3P = .0075;
!   HP*H/H2P = 6.2 * 10^-8);
!   H*P/HP = 4.8*10^-13;
!   H = 10 ^-8;
!   H3P + H2P + HP + P = .1;

! The very small numbers make this a difficult problem to solve with default 
  tolerances. Doing a log transformation helps the scaling, + makes it almost linear;
   LH2P + LH - LH3P = @LOG( .0075);
   LHP + LH - LH2P = @LOG( 6.2 * 10^-8);
   LH + LP - LHP = @LOG( 4.8 * 10^-13);
   LH = @LOG( 10 ^-8);

! Convert back to original variables;
   H   = @EXP( LH);
   P   = @EXP( LP);
   HP  = @EXP( LHP);
   H2P = @EXP( LH2P);
   H3P = @EXP( LH3P);
   H3P + H2P + HP + P = .1;

! Must unconstrain log variables;
 @FREE( LH2P); @FREE( LH); @FREE( LH3P); 
 @FREE( LHP); @FREE( LP);

! Solution should be: LH2P= -4.2767, LH= -18.4207,
  LH3P= -17.8045, LHP= -2.4522, LP= -12.3965;

! Keywords: Chemical equilibrium, Equilibrium, Scaling, Logarithmic scaling;