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."

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

When you reinstalled with R2023A, did you first manually delete all the old installation folders that were left behind by R2023B?
and this code in another .m file (to use in the fminunc)
Where is this additional file located in relation to your main script? Are they both in the same folder? Also, does anything change when you insert a call to the function from the script-
x = -3:0.1:3 ;
y = (x+1) .* (x+1) +1;
%% Next find the unconstrained minimum
x0 = 3;
hw2_example(x0) %%%%< insert this
options = optimoptions('fminunc', 'Display', 'iter', 'Algorithm', 'quasi-newton');
[xoptimal, optimal_cost] = fminunc(@hw2_example_cost, x0, options)
The code seems to be working here as well, see the edit above.
I suspect there has been mix up with some built-in functions. Follow the instructions provided by Steven Lord in this answer - https://in.mathworks.com/matlabcentral/answers/1443459-error-in-fminunc-function-line-477#answer_1218503
The most common cause of that error message, is running out of memory.
... It seems unlikely that the above code would run out of memory, though.
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
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.

Categories

Products

Release

R2023a

Asked:

on 5 Feb 2024

Moved:

on 5 Feb 2024

Community Treasure Hunt

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

Start Hunting!