MATLAB: Error fsolve undefined function or variable x.

fsolveMATLAB

Could anyone say to me which is the problem here? Thanks in advance.
function F = prova(x)
k=1.38*10^(-23);
Tc=298.15;
q=1.6*10^(-19);
VT=k*Tc/q;
Isc=5.96;
Voc=62.18;
Imp=5.65;
Vmp=50.61;
Rs=0;
F(1)= x(1)-Isc-x(2)*(exp((Isc*Rs)/(x(3)*VT))-1);
F(2)= x(1)-Imp-x(2)*(exp((Vmp+Imp*Rs)/(x(3)*VT))-1);
F(3)= x(1)-x(2)*(exp((Voc)/(x(3)*VT))-1);
F=[F(1),F(2),F(3)];
x0=[6 0.5 1.2];
x=fsolve(@prova,x0);
end

Best Answer

One problem is that you are calling fsolve from within the ‘prova’ function.
Try this:
function F = prova(x)
k=1.38E-23;
Tc=298.15;
q=1.6E-19;
VT=k*Tc/q;
Isc=5.96;
Voc=62.18;
Imp=5.65;
Vmp=50.61;
Rs=0;
F(1)= x(1)-Isc-x(2)*(exp((Isc*Rs)/(x(3)*VT))-1);
F(2)= x(1)-Imp-x(2)*(exp((Vmp+Imp*Rs)/(x(3)*VT))-1);
F(3)= x(1)-x(2)*(exp((Voc)/(x(3)*VT))-1);
F=[F(1),F(2),F(3)];
end
x0=[6 0.5 1.2];
x=fsolve(@prova,x0);
However solving that problem throws::
Error using trustnleqn (line 28)
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
Running this:
Q = prova(x0)
produces:
Q =
0.04 -Inf -Inf
This is most likely due to the vanishingly small values for ‘k’ and ‘q’. You have to solve that. (Scaling may be an option, such that al the constants are multiplied by 1E+10 or some such, then the ‘x’ values are appropriately re-scaled, if necessary.)