Error fsolve undefined function or variable x.

3 vues (au cours des 30 derniers jours)
Matteo Aversa
Matteo Aversa le 6 Fév 2020
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

Réponse acceptée

Star Strider
Star Strider le 6 Fév 2020
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.)

Plus de réponses (1)

Alex Sha
Alex Sha le 9 Fév 2020
taking initial start-values as:
x0=[6 0.5 150];
will produce:
x1: 5.96
x2: 7.50486851347978E-7
x3: 152.194203428967

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Tags

Produits


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by