Error fsolve undefined function or variable x.

조회 수: 3 (최근 30일)
Matteo Aversa
Matteo Aversa 2020년 2월 6일
답변: Alex Sha 2020년 2월 9일
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

채택된 답변

Star Strider
Star Strider 2020년 2월 6일
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.)

추가 답변 (1개)

Alex Sha
Alex Sha 2020년 2월 9일
taking initial start-values as:
x0=[6 0.5 150];
will produce:
x1: 5.96
x2: 7.50486851347978E-7
x3: 152.194203428967

태그

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by