From 9e69e91f91f3fda5ceaf582c77f0a676998943bf Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Sat, 12 Nov 2016 10:15:21 -0700 Subject: [PATCH 1/2] Improve precision of v_from_i for large arguments Number of iterations of Newton method should increase with the order of the argument, to maintain precision. Not expected to have a significant effect on most calculated IV curves. --- pvlib/pvsystem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index ba64fc200b..63aae7883d 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -1843,7 +1843,8 @@ def v_from_i(resistance_shunt, resistance_series, nNsVth, current, # evaluation (above) results in NaN from overflow, 3 iterations # of Newton's method gives approximately 8 digits of precision. w = logargW - for i in range(0, 3): + order = np.log10(w) + for i in range(0, 3*order): w = w * (1 - np.log(w) + logargW) / (1 + w) lambertwterm_log = w From 3f9f37fd918cb7bfd3f744fac5388ccf52d5448e Mon Sep 17 00:00:00 2001 From: cwhanse Date: Wed, 16 Nov 2016 10:37:45 -0700 Subject: [PATCH 2/2] Fix type, add whatsnew note --- docs/sphinx/source/whatsnew/v0.4.2.txt | 2 ++ pvlib/pvsystem.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.4.2.txt b/docs/sphinx/source/whatsnew/v0.4.2.txt index fe12d53ad6..6572adabb9 100644 --- a/docs/sphinx/source/whatsnew/v0.4.2.txt +++ b/docs/sphinx/source/whatsnew/v0.4.2.txt @@ -41,6 +41,7 @@ Enhancements * Added name attribute to ModelChain and PVSystem. (:issue:`254`) * Restructured API section of the documentation so that there are separate pages for each function, class, or method. (:issue:`258`) +* Improved convergence of lambertw function (:issue: '260') Code Contributors @@ -49,3 +50,4 @@ Code Contributors * Uwe Krien * Will Holmgren * Volker Beutner +* Cliff Hansen diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 63aae7883d..47dfbcabec 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -1843,7 +1843,7 @@ def v_from_i(resistance_shunt, resistance_series, nNsVth, current, # evaluation (above) results in NaN from overflow, 3 iterations # of Newton's method gives approximately 8 digits of precision. w = logargW - order = np.log10(w) + order = np.ceil(np.log10(w)).astype(int) for i in range(0, 3*order): w = w * (1 - np.log(w) + logargW) / (1 + w) lambertwterm_log = w