jamesorr / CO2SYS-MATLAB

CO2SYS software for MATLAB (or octave) to compute variables of ocean CO2 system
MIT License
29 stars 11 forks source link

Fix inexact slope for determining pH #7

Open briochemc opened 2 years ago

briochemc commented 2 years ago

Probably fixes #3.

I tried to make this PR as minimal as possible.

Hopefully this change is sufficient! Quick testing shows that the new slope is accurate close to machine precision (relative error bounded by about 1e-14).

I think this should only make pH solves a little bit more accurate where it used to be inaccurate (e.g., for extreme input) at the price of a few extra computations that I hope incur only a marginal cost. This also potentially reduces the number of Newton iterations, so it could turn out a bit more efficient.

But just to be sure, could someone check that I did not mess anything up? Is there a test suite available somewhere?

mvdh7 commented 2 years ago

Hey, nice work @briochemc! Would suggest also adding this to the more recently updated CO2SYSv3 here: https://github.com/jonathansharp/CO2-System-Extd

briochemc commented 2 years ago

Oh I had no idea this existed! I'll take look soon...

Is it worth adding some link pointing users to the new version in the ReadMe?