Failure in initial objective function evaluation. FSOLVE cannot continue.
Show older comments
I have some problems with fsolve:
My function:
function F = simple(x)
global c1 c2
F(1) = x(1)-c1;
F(2) = x(2)-c2;
end
Here is my code that calls this function in my main file:
global c1 c2
c1 = 150
c2 = 130
options = optimoptions('fsolve','Display','iter');
[x,fval,exitflag,output] = fsolve(@simple,[0 0],options)
Matlab's error message is as follows. If this is caused by some other part of my code. What can be the cause? How do I locate and correct that part? Thank you very much.
Error message:
Unable to perform assignment because the indices on the left side are not
compatible with the size of the right side.
Error in simple (line 4)
F(1) = x(1)-c1;
Error in fsolve (line 264)
fuser = feval(funfcn{3},x,varargin{:});
Error in nlogit (line 478)
[x,fval,exitflag,output] = fsolve(@simple,[0 0],options)
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
2 Comments
Ludovico Cucciniello
on 14 Feb 2022
The problem might be the way you're defining the variables c1 and c2. Anyway, I tried this and seems to work.
c = [150, 300];
x0 = [0,0];
options = optimoptions('fsolve','Display','iter');
[x,fval,exitflag,output] = fsolve(@simple,x0,options,c);
function F = simple(x,c)
F(1) = x(1)-c(1);
F(2) = x(2)-c(2);
end
Chang Li
on 14 Feb 2022
Accepted Answer
More Answers (0)
Categories
Find more on Solver Outputs and Iterative Display 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!