Failure in initial objective function evaluation. FSOLVE cannot continue.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Chang Li
am 14 Feb. 2022
Kommentiert: Chang Li
am 14 Feb. 2022
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 Kommentare
Ludovico Cucciniello
am 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
Akzeptierte Antwort
Walter Roberson
am 14 Feb. 2022
Works for me.
format long g
global c1 c2
c1 = 150
c2 = 130
options = optimoptions('fsolve','Display','iter');
[x,fval,exitflag,output] = fsolve(@simple,[0 0],options)
function F = simple(x)
global c1 c2
F(1) = x(1)-c1;
F(2) = x(2)-c2;
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!