From 76a0b6227e0894ae12aa5bcc33548d59ea96f3b0 Mon Sep 17 00:00:00 2001
From: Willi Mutschler <willi@mutschler.eu>
Date: Tue, 4 Jan 2022 14:33:05 +0100
Subject: [PATCH] lsqnonlin only supported for method_of_moments

(cherry picked from commit 7f3bc60ce0c0b455396e2008cf0c0c27de936e87)
---
 doc/manual/source/the-model-file.rst            | 2 +-
 matlab/optimization/dynare_minimize_objective.m | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst
index ec6472bd56..6ee4ec2698 100644
--- a/doc/manual/source/the-model-file.rst
+++ b/doc/manual/source/the-model-file.rst
@@ -5984,7 +5984,7 @@ block decomposition of the model (see :opt:`block`).
                 routine (available under MATLAB if the Optimization Toolbox is
                 installed; available under Octave if the `optim
                 <https://octave.sourceforge.io/optim/>`__ package from
-                Octave-Forge is installed).
+                Octave-Forge is installed). Only supported for ``method_of_moments``. 
 
            ``101``
 
diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m
index 06ecb9be9c..62f7019ae7 100644
--- a/matlab/optimization/dynare_minimize_objective.m
+++ b/matlab/optimization/dynare_minimize_objective.m
@@ -542,6 +542,9 @@ switch minimizer_algorithm
     opt_par_values = opt_par_values(:);
   case 13
     % Matlab's lsqnonlin (Optimization toolbox needed).
+    if ~isfield(options_,'mom')
+        error('Option mode_compute=13 is available only for method_of_moments estimation.')
+    end
     if isoctave && ~user_has_octave_forge_package('optim')
         error('Option mode_compute=13 requires the optim package')
     elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox')
-- 
GitLab