Nonlinear equations & fsolve. Error "Failure in initial objective function evaluation. FSOLVE cannot continue."

5 vues (au cours des 30 derniers jours)
Hello there, I'm trying to solve a set of nonlinear equations with fsolve (I'm quite new to Matlab and just tried this one out, not sure if fsolve fits my problem right, maybe someone has an even better idea?) and it returns the error shown above. This is my function:
function F = root2d(x)
Pabs=[100, 200, 400, 600, 800, 1000, 1200, 1400];
P_loss_PV2BAT=[81.1511, 90.8539, 109.6374, 127.5911, 144.7151,...
161.0094, 176.4739, 191.1088];
F(1)=Pabs(1)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(1)*(x(7)+x(8))-(P_loss_PV2BAT(1)*1000);
F(2)=Pabs(2)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(2)*(x(7)+x(8))-(P_loss_PV2BAT(2)*1000);
F(3)=Pabs(3)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(3)*(x(7)+x(8))-(P_loss_PV2BAT(3)*1000);
F(4)=Pabs(4)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(4)*(x(7)+x(8))-(P_loss_PV2BAT(4)*1000);
F(5)=Pabs(5)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(5)*(x(7)+x(8))-(P_loss_PV2BAT(5)*1000);
F(6)=Pabs(6)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(6)*(x(7)+x(8))-(P_loss_PV2BAT(6)*1000);
F(7)=Pabs(7)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(7)*(x(7)+x(8))-(P_loss_PV2BAT(7)*1000);
F(8)=Pabs(8)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Pabs(8)*(x(7)+x(8))-(P_loss_PV2BAT(8)*1000);
Out of the 8 unknowns, two are variables and 6 are coefficients. I didn't know how else to fit them into fsolve so I just made them all into variables... And thats how I call it:
fun=@root2d;
x0=[0,0];
options = optimoptions('fsolve','Display','iter');
x=fsolve(fun,x0,options)
There must already be something wrong with the function, because it keeps saying:
Index exceeds matrix dimensions.
Error in root2d (line 9)
F(1)=Pabs(1)^2*((x(1)/x(2))+(x(3)/x(4)))+x(5)*x(2)+x(6)*x(4)+...
Error in fsolve (line 230)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
It might also be that I'm completely wrong using fsolve here, but I don't know how else to solve this problem. Any ideas would be greaty appreciated!

Réponse acceptée

Torsten
Torsten le 27 Avr 2018
x0 must have 8 elements, not 2.
Best wishes
Torsten.
  1 commentaire
Selina Maier
Selina Maier le 2 Mai 2018
Modifié(e) : Selina Maier le 2 Mai 2018
Hi Torsten, thanks for your answer! Of course you are right, I changed x0 to a vector of 8 elements... There was another error, this one:
Error using trustnleqn (line 28)
Objective function is returning undefined values at initial point.
FSOLVE cannot continue.
Error in fsolve (line 388)
trustnleqn(funfcn,x,verbosity,gradflag,options,defaultopt,f,JAC,...
It could be solved by changing the initial values in x0 from zeros to ones.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by