I have this algorithm:
function F=giaiphuongtrinh(x) Pv=5; Pred=6; Pl=10; Ebmax=20; Ebmin=2; Eb=2; Pdiesel=2; Edum=0; if (Pv+Pred)>=Pl x(2)=Pv+Pred-Pl Ech=x(2) if Ech<=(Ebmax-Eb) Eb=Eb+Ech x(3)=0 else Eb=Ebmax x(3)=Ech-(Ebmax-Eb) end else x(1)=Pl-(Pv+Pred) Edch=x(1) if Edch<=(Eb-Ebmin) Eb=Eb-Edch else Eb=Ebmin end end F=(Pl-(Pv+Pred+Pdiesel+x(1)-x(2)-x(3)))
I ran:
x0=[0;0;0];options = optimoptions('fsolve','Display','iter');[x,fval] = fsolve(@giaiphuongtrinh,x0,options)
and the result is:
4 20 3.81809e-28 1.95e-14 1e-06 1.97781e-09Equation solved.fsolve completed because the vector of function values is near zeroas measured by the default value of the function tolerance, andthe problem appears regular as measured by the gradient.<stopping criteria details>x = -2.0000 0 0fval = -1.9540e-14
I think it must be another result. Do you see something wrong? Please help me. Thank you so much.
Best Answer