I get this error when trying to use fminunc "Error using message/getString Unable to load a message catalog 'optim:fminusub'. Please check the file location and format."

31 views (last 30 days)
I have this code in one .m file :
%%HW 2 example
% first define polynomial function and display
clear
x = -3:0.1:3 ;
y = (x+1) .* (x+1) +1;
%% Next find the unconstrained minimum
x0 = 3;
options = optimoptions('fminunc', 'Display', 'iter', 'Algorithm', 'quasi-newton');
[xoptimal, optimal_cost] = fminunc(@hw2_example_cost, x0, options)
First-order Iteration Func-count f(x) Step-size optimality 0 2 17 8 1 4 10 0.125 6 2 6 1 1 2.24e-07 Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
xoptimal = -1.0000
optimal_cost = 1.0000
figure
plot(x,y,'k-'); grid; hold on
h1 = plot(xoptimal, optimal_cost,'ko');
set(h1, 'markersize', 10, 'linewidth', 2, 'MarkerFaceColor', '#D9FFFF');
title('Unconstrained Optimization Minimum')
-------------------------------------------------------------------------
and this code in another .m file (to use in the fminunc)
function cost = hw2_example_cost(x)
cost = (x + 1) * (x + 1) + 1;
end
-----------------------------------------------------------------------------
this is the error message in the command line (when my proffesor runs it he gets it to work no problem)
Error using message/getString
Unable to load a message catalog 'optim:fminusub'. Please check the file location and format.
Error in createExitMsg (line 32)
basicMsg = getString(message(basicMsgArgs{:}));
Error in fminusub (line 322)
output.message = createExitMsg(msgData{:});
Error in fminunc (line 496)
[x,FVAL,GRAD,HESSIAN,EXITFLAG,OUTPUT] = fminusub(funfcn,x, ...
Error in hw2_example (line 12)
[xoptimal, optimal_cost] = fminunc('hw2_example_cost', x0, options)
--------------------------------------------------------------------------------------------------------------------
I was using MATLAB2023B at first but since i got this error i switched to my proffesors version (2023A) and i still get the same error. And no i did not mix different verisons files of matlab together or do anything weird during instalation process. I only have 1 version of matlab downloaded right now.
  6 Comments
Raad Abusaad
Raad Abusaad on 5 Feb 2024
Moved: Walter Roberson on 5 Feb 2024
yes both .m files are in the same folder and i uninstalled matlab using the control panel uninstall program thing widows has and then i manually went into my c drive and uninstalled any remnant files. I solved this problem by installing the Optimization tool box
Dyuman Joshi
Dyuman Joshi on 5 Feb 2024
Weird. If you did not have the Optimization toolbox installed, you should have gotten an error like this when you ran your code -
" 'fminunc' requires Optimization Toolbox. "

Sign in to comment.

Answers (1)

Raad Abusaad
Raad Abusaad on 5 Feb 2024
I solved my problem by installing the optimization toolbox

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!