From a89f21b53d4270e7f64d3054678965d7825ff66e Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Fri, 22 Jan 2021 14:20:23 +0100
Subject: [PATCH] solvopt.m: prevent returning with inf

---
 matlab/optimization/solvopt.m | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/matlab/optimization/solvopt.m b/matlab/optimization/solvopt.m
index a069e6dc17..56050b0740 100644
--- a/matlab/optimization/solvopt.m
+++ b/matlab/optimization/solvopt.m
@@ -678,6 +678,9 @@ while 1
                 end
                 if ksm || kc>=mxtc
                     exitflag=-3;
+                    % don't return with NaN or Inf despite error code
+                    x=x1;
+                    f=f1;                  
                     if trx
                         x=x';
                     end
-- 
GitLab