Too many output arguments in fsolve

4 views (last 30 days)
Dear all,
I trying to solve a system of algebraic equations with the fsolve function. I get the following error message, both with my own script and the example script provided with the documentation (SolutionwithNondefaultOptionsExample.m)
Error using prepareOptionsForSolver
Too many output arguments.
Error in fsolve (line 157)
[options, optionFeedback] = prepareOptionsForSolver(options, 'fsolve');
Error in SolutionWithNondefaultOptionsExample (line 32)
x = fsolve(fun,x0,options)
The function prepareOptionsForSolver is not documented, but the input from fsolve seems to correspond to what is required. Since this also arises in an example from the documentation, there should not be any problems with the syntax.
Does anybody know how to fix this problem? Do you know alternatives? I have tried using the vpasolve function, but my equations include the incomplete gamma function that cannot handle symbolics.
Thanks, Jens
  4 Comments
Ameer Hamza
Ameer Hamza on 1 Apr 2020
Edited: Ameer Hamza on 1 Apr 2020
I am using R2020a so I cannot directly check the issue. Can you run
edit prepareOptionsForSolver
In command window and paste the first line in your comment (function definition) here.
Jens Turowski
Jens Turowski on 1 Apr 2020
Here you go:
function options = prepareOptionsForSolver(options, solverName)
%
%PREPAREOPTIONSFORSOLVER Prepare options for solver
%
% OPTIONS = PREPAREOPTIONSFORSOLVER(OPTIONS,
% SOLVERNAME) performs tasks to ensure the options are set up for use by
% the solver. The following tasks are performed:-
%
% * If a user has passed a SolverOptions object, first ensure that it is
% a set of options for fseminf.
%
% * If a user has passed a SolverOptions object, now extract the options
% structure from the object.
% Copyright 2012-2018 The MathWorks, Inc.
% If a user has passed a structure, we cannot tell whether a user wrote the
% code that passes the structure before or after 16a. In this case, we
% assume that the code was written before 16a and set TolFunValue to
% TolFun, if TolFunValue is not in options. We also convert any string
% data types to character arrays.

Sign in to comment.

Accepted Answer

Jens Turowski
Jens Turowski on 1 Apr 2020
Thanks, found a copy of a 2016 release fsolve function in one of the local folders. Thanks for your time and effort. :o) Jens
  2 Comments
John D'Errico
John D'Errico on 1 Apr 2020
Then please accept the answer by Ameer, which explicitly tells you to look for other functions or scripts named fsolve, however they got there. Note that putting an old copy of a toolbox function in another directory was a bad idea anyway. It will cause problems down the line.

Sign in to comment.

More Answers (1)

Ameer Hamza
Ameer Hamza on 1 Apr 2020
It appears that you have somehow overwritten the fsolve function provided by MATLAB. This line show
function options = prepareOptionsForSolver(options, solverName)
That prepareOptionsForSolver only gives one output. But In your error message shows that in your fsolve function, there is a line as follow
[options, optionFeedback] = prepareOptionsForSolver(options, 'fsolve');
which does not match the definition of prepareOptionsForSolver. I checked the definition of fsolve in R2020a, and it contains
options = prepareOptionsForSolver(options, 'fsolve');
I recommend first to check if MATLAB is using correct fsolve function by typing
which fsolve
If it points to MATLAB toolbox directory then I recommend to reinstall MATLAB to recover the original definition of fsolve
  2 Comments
Jens Turowski
Jens Turowski on 1 Apr 2020
Thanks for the answer, but this cannot be the case. I installed Matlab on this computer yesterday and it the first project I am doing with the new installation. I definately have not changed any of the functions.
Ameer Hamza
Ameer Hamza on 1 Apr 2020
Can you show the output of
which fsolve

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!