MATLAB Answers

Why do I get an error when I try to use optimization functions from base MATLAB 7.14 (R2012a)?

111 ビュー (過去 30 日間)
When I try to use any of the optimization functions from base MATLAB 7.14 (R2012a) I get either of the following errors depending on the function used:
Undefined function 'optimset' for input arguments of type 'char'.
Undefined function 'optimset' for input arguments of type 'struct'.
Undefined function 'fzero' for input arguments of type 'function_handle'.
Undefined function 'fminbnd' for input arguments of type 'function_handle'.
Undefined function 'fminsearch' for input arguments of type 'function_handle'.
Undefined function 'lsqnonneg' for input arguments of type 'function_handle'.
These error messages are seen primarily just after migration from a previous version of MATLAB due to a path issue.

採用された回答

MathWorks Support Team
MathWorks Support Team 2012 年 7 月 26 日
In MATLAB 7.14 (R2012a) the base MATLAB optimization related functions were moved from the following location
>> [matlabroot '\toolbox\matlab\funfun\']
to
>> [matlabroot '\toolbox\matlab\optimfun\']
Since MATLAB copies all the preferences from the previous release to the new preference directory the issue is caused because MATLAB is unable to find these function.
The fix for this issue is to execute the following commands so that the path is restored to default and the toolbox cache is updated:
>> restoredefaultpath
>> rehash toolboxcache
Since restoring the default path will remove any personal path changes, you can manually fix this by navigating to:
cd(matlabroot);
cd toolbox;
cd matlab;
addpath(genpath('optimfun'));
savepath;
rehash;

  0 件のコメント

サインイン to comment.

その他の回答 (3 件)

Chandrasekar Mallapu
Chandrasekar Mallapu 2018 年 1 月 25 日
Reactor Modeling using Matlab.
When i try to use the options function using MATLAB R2011b I get the following errors.
'Undefined function 'optimoptions' for input arguments of type 'char'

  4 件のコメント

表示 1 件の古いコメント
Nikita Nikitov
Nikita Nikitov 2018 年 5 月 30 日
Hey, I'm using 2017a and this issue is still there.
BR, Nikita
Steven Lord
Steven Lord 2018 年 5 月 30 日
The optimoptions function was introduced in Optimization Toolbox in release R2013a. If it is not available to you in release R2017a, you likely do not have Optimization Toolbox installed and/or licensed. You can check if the toolbox is installed using the ver function and you can test if it is licensed using the license function.
Kyle Perry
Kyle Perry 2018 年 5 月 30 日
Hi Nikita,
Please contact MathWorks support directly so we can try and help resolve this issue.

サインイン to comment.


Tech Support
Tech Support 2018 年 4 月 13 日
Hi Tanmoy,
If you are still experiencing this issue, please contact MathWorks support:
-Justin
MathWorks Installation & Licensing Support

  0 件のコメント

サインイン to comment.


65465 6465
65465 6465 2019 年 1 月 30 日
In matlab 2013a I get a similar error:
Undefined function 'fminunc' for input arguments of type 'function_handle'.
I have Optimization Toolbox, how can I solve it?
Code is below,it's from Andrew Ng Maching Leraing exc_2.
% Set options for fminunc
options = optimset('GradObj', 'on', 'MaxIter', 400);
% Run fminunc to obtain the optimal theta
% This function will return theta and the cost
[theta, cost] = ...
fminunc(@(t)(costFunction(t, X, y)), initial theta, options);

  1 件のコメント

65465 6465
65465 6465 2019 年 2 月 1 日
Sorry, I have a mistake in my costFunction, It's working now.

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2012a

Translated by