Skip to content

[Suggestion] More robust root finding for pH evaluation #3

@briochemc

Description

@briochemc

Not sure this is useful to anyone but me, but I found out that sometimes the Newton solver for evaluating pH hangs when the other tracer values are outside of some acceptable range. I think this might be due to the current backtracking implementation where the Newton step is halved until the pH step deltapH is less than 1:

CO2SYS-MATLAB/src/CO2SYS.m

Lines 1525 to 1530 in b62ad9e

deltapH = Residual./Slope; % this is Newton's method
% to keep the jump from being too big;
while any(abs(deltapH) > 1)
FF=abs(deltapH)>1; deltapH(FF)=deltapH(FF)./2;
end
pHx = pHx + deltapH; % Is on the same scale as K1 and K2 were calculated...

However, I think that even an overshoot in deltapH of less than 1 can still be too large and result in some never-ending cycle (illustrated below).

I think this is because the criteria for reducing the step size should be on the next residuals. Thus, maybe this backtracking line search could be replaced with one for which the criteria would be on the next residual instead?

Another option would be to write a function that returns the residual for a given pH and then use an existing Newton-solver that already has that criteria implemented (e.g., C. T. Kelley's nsold.m, which uses a quadratic approximation of the residual along the Newton-step direction for a rather efficient backtracking IMHO).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions