Failure in initial objective function evaluation. FSOLVE cannot continue.

i set two files as main.m and root.m.
Here are my codes.
When I runs main.m,it keeps telling me that "Failure in initial objective function evaluation. FSOLVE cannot continue."
Hope someone can help me with that.Thanks!
[main.m]
clear all; clc
fun = @root;
x0 = [2e-5,0.04,0.1524,1.0194,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
x = fsolve(fun,x0)
[root.m]
global Tinlet Treact T0
Tinlet = 273+25 ;%K
Treact = 273+150 ;%K
T0 = 273+25;%K
global ki1 ki2 kp11 kp12 kp21 kp22 ktal kd ki10 kp110 kp120 kp210 kp220 ktal0 kd0 Eki1 Ekp11 Ekp12 Ekp21 Ekp22 Ektal Ekd R
R = 8.314;
ki10 = 13.0;
Eki1 = 10000;
ki1 = ki10 * exp(-Eki1*(1/Treact-1/T0));
ki2 = 0.0;
kp110 = 3.70e+05;
Ekp11 = 10000;
kp11 = kp110 * exp(-Ekp11*(1/Treact-1/T0));
kp120 = 673;
Ekp12 = 10000;
kp12 = kp120 * exp(-Ekp12*(1/Treact-1/T0));
kp210 = 1.36e+03;
Ekp21 = 10000;
kp21 = kp210 * exp(-Ekp21*(1/Treact-1/T0));
kp220 = 46 ;
Ekp22 = 10000;
kp22 = kp220 * exp(-Ekp22*(1/Treact-1/T0));
ktal0 = 2.5;
Ektal = 10000;
ktal = ktal0 * exp(-Ektal*(1/Treact-1/T0));
kd0 = 1.0e-04;
Ekd = 10000;
kd = kd0 * exp(-Ekd*(1/Treact-1/T0));
function F = fun(x)
F(1) =ktx(2)*x(5)+x(6)*x(2)-ki1*x(1)*x(3)-ki2*x(1)*x(4)-x(14);
F(2) =UDSI0 - x(14)*stoptime-x(1);
F(3) =ktx(2)*x(2)*(x(6)+x(7))-x(15);
F(4) =UDSI1 - x(15)*stoptime-x(2);
F(5) =(ki1*x(1)+kp11*x(5)+kp21*x(6))*x(3)-x(16);
F(6) =UDSI2 - x(16)*stoptime-x(3);
F(7) =(ki2*x(1)+kp12*x(5)+kp22*x(6))*x(4)-x(17);
F(8) =UDSI3 - x(17)*stoptime-x(4);
F(9) =ki1*x(1)*x(3)+kp21*x(6)*x(3)-kp12*x(5)*x(4)-(ktx(2)*x(2)+kd)*x(5)-x(18);
F(10) =UDSI4 - x(18)*stoptime-x(5);
F(11) =ki2*x(1)*x(4)+kp12*x(5)*x(4)-kp21*x(6)*x(3)-(ktx(2)*x(2)+kd)*x(6)-x(19);
F(12) =UDSI5 - x(19)*stoptime-x(6);
F(13) =ki1*x(1)*x(3)+kp11*x(5)*x(3)+kp21*(x(7)+x(6))*x(3)-kp12*x(7)*x(4)-(ktx(2)*x(2)+kd)*x(7)-x(20);
F(14) =UDSI6 - x(20)*stoptime-x(7);
F(15) =ki2*x(1)*x(4)+kp22*x(6)*x(4)+kp12*(first_lamada2+x(5))*x(4)-kp21*x(7)*x(3)-(ktx(2)*x(2)+kd)*first_lamada2-x(21) ;
F(16) =UDSI7 - x(21)*stoptime-x(8);
F(17) =ki1*x(1)*x(3)+kp11*(2*x(7)+x(5))*x(3)+kp21*(x(10)+2*x(8)+x(6))*x(3)-kp12*x(9)*x(4)-(ktx(2)*x(2)+kd)*x(9)-x(22);
F(18) =UDSI8 - x(22)*stoptime-x(9);
F(19) =ki2*x(1)*x(4)+kp22*(2*x(8)+x(6))*x(4)+kp12*(x(9)+2*x(7)+x(5))*x(4)-kp21*x(10)*x(3)-(ktx(2)*x(2)+kd)*x(10)-x(23);
F(20) =UDSI9 - x(23)*stoptime-x(10);
F(21) =(ktx(2)*x(2)+kd)*(x(5)+x(6))-x(24);
F(22) =UDSI10 - x(24)*stoptime-x(11);
F(23) =(ktx(2)*x(2)+kd)*(x(7)+x(8))-x(25);
F(24) =UDSI11 - x(25)*stoptime-x(12);
F(25) =(ktx(2)*x(2)+kd)*(x(9)+x(10))-x(26);
F(26) =UDSI12 - x(25)*stoptime-x(13);
F = [F(1),F(2),F(3),F(4),F(5),F(6),F(7),F(8),F(9),F(10),F(11),F(12),F(13),F(14),F(15),F(16),F(17),F(18),F(19),F(20),F(21),F(22),F(23),F(24),F(25),F(26)];
end

5 commentaires

The fiunction handle you must pass to fsolve is @fun, not @root.
@ma xueyi, what are UDSI0,UDSI1,...UDSI12, stoptime,and ktx(2) ?
i forgot to tell the number of UDSI0,UDSI1...
ktx=ktal,i dont know why it changes when i copied the codes from python
You haven't given those data yet.
Comment posted as flag by ma xueyi:
thanks, i provided the data otherplace

Connectez-vous pour commenter.

 Réponse acceptée

You provide a handle to a script. This cannot work, because fsolve expects a function handle. Most likely you want:
fsolve(@fcn, x0)
instead. Currently the constants are not visible in the function fcn. Maybe you want to declare the variables as globals there also? What is stoptime?
Whenever you mention an error in the forum, paste a copy of the complete error message, not just some parts of it.

Plus de réponses (1)

Actully my codes are now running successfully.
Howerver its answer is not reliable(exitflag = 0)
No matter how big i change the 'MaxFunEvals' and 'MaxIterations' to be, the first-order optimality never changed.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by