I am using fsolve and receiving errors

I have the following function which i am defining some of the parameters as follows:
function F = solar5d(x)
q = 1.60217662*10^-19;
k = 1.38064852*10^-23;
T = 298.15; % Temperature in degrees 25. This one is in Kelvin.
Ns = 72;
Np = 1;
Voc = 44.6;
Vm = 35.43;
Isc = 5.43;
Im = 4.95;
n = 1.086;
These are my unknown parameters i am looking for:
Iph = x(1);
Io = x(2);
Rs = x(3);
Rp = x(4);
Vt = x(5);
The following are the six questions i have to solve the system:
F(1) = Vt - n*k*T/q;
F(2) = Np*Iph - Np*Io*(exp(Voc/Ns*Vt)-1) - (Np*Voc)/(Ns*Rp);
F(3) = Np*Iph - Np*Io*(exp((Isc*Rs)/(Np*Vt)) - 1) - (Isc*Rs)/Rp - Isc;
F(4) = Np*Iph - Np*Io*(exp(((Vm/Ns)+(Im*Rs)/Np)/Vt) - 1) - Np*((((Vm/Ns)+((Im*Rs)/Np))/Rp)) - Im;
F(5) = (((Np/Ns*Vt)*Io*(exp((Vm + ((Im*Ns*Rs)/Np))/Ns*Vt)) + (1/(Ns*Rp)/Np))/(1 + (Rs*Vt)*Io*(exp((Vm + ((Im*Ns*Rs)/Np))/Ns*Vt)) + (Rs/Rp))) - (Im/Vm);
F(6) = (((-Np/Ns*Vt)*Io*(exp(Voc/Ns*Vt)) - (1/Ns*Rp/Np)) / (1 + (Rs/Vt)*Io*(exp(Voc/Ns*Vt)) + (Rs/Rp))) + 1/Rs;
end
But i am receiving the following error:
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle
non-square systems; using Levenberg-Marquardt algorithm instead.
> In fsolve (line 298)
Error using levenbergMarquardt (line 16)
Objective function is returning undefined values at initial point.
fsolve cannot continue.
Error in fsolve (line 397)
levenbergMarquardt(funfcn,x,verbosity,options,defaultopt,f,JAC,caller,
...
Please could you help me to solve my problem??
Thanks in advance.
Regards,
Charalampos

2 Comments

You did not happen to show you call to fsolve, with your initial conditions.
Note that
q = 1.60217662*10^-19;
requires three numbers and two expensive operations to generate the output value, whereas
q = 1.60217662e-19;
is efficiently defined as that value, without any operations.

Sign in to comment.

Answers (2)

Add
disp(F)
at the end of solar5d.
I suspect that the array F contains Inf, NaN or something similar.
Take care that your initial values for the variables don't produce division by zero or undefined expressions.
Best wishes
Torsten.

7 Comments

Hello Torsten
I am calling the following in the matlab command:
fun = @solar5d; x0 = [0,0,0,0,0]; x = fsolve(fun,x0)
But i am receiving the error i mentioned above
Torsten
Torsten on 24 Nov 2017
Edited: Torsten on 24 Nov 2017
And what do you get for F in solar5d ?
You divide by Rp, Rs and Vt. This is not possible for your vector of initial values.
Best wishes
Torsten.
>> fun = @solar5d;
>> x0 = [0,0,0,0,0];
>> x = fsolve(fun,x0) -0.0279 -Inf NaN NaN NaN NaN
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
> In fsolve (line 298) Error using levenbergMarquardt (line 16) Objective function is returning undefined values at initial point. fsolve cannot continue.
Error in fsolve (line 397) levenbergMarquardt(funfcn,x,verbosity,options,defaultopt,f,JAC,caller, ...
The pictures i post above are the equations i am using in the algorithm i post. The first 3 equations i rearranged them to be equal to zero the 4 one the same and then i choose question (15) to be as my fifth equation and i rearrange it to be equal to zero again.

Sign in to comment.

It seems that you try to solve an overdetermined system. You have six equations in five unknowns. You should re-examine your problem to see if one of your equations is superfluous.
Also, it is good practice (although not strictly necessary) to pre-allocate memory to F: Insert the command
F = zeros(6,1) % Or zeros(5,1)?
before you define the components of F.

9 Comments

Hello Are,
I could take out equation F(1) i can calculate it manually and define the value instead of having the equation there as an unknown parameter.
function F = solar5d(x)
% q = 1.60217662*10^-19;
% k = 1.38064852*10^-23;
% T = 298.15; % Temperature in degrees 25. This one is in Kelvin.
Ns = 72;
Np = 1;
Voc = 44.6;
Vm = 35.43;
Isc = 5.43;
Im = 4.95;
% n = 1.086;
Vt = 0.028;
Iph = x(1);
Io = x(2);
Rs = x(3);
Rp = x(4);
F(1) = Np*Iph - Np*Io*(exp(Voc/Ns*Vt)-1) - (Np*Voc)/(Ns*Rp);
F(2) = Np*Iph - Np*Io*(exp((Isc*Rs)/(Np*Vt)) - 1) - (Isc*Rs)/Rp - Isc;
F(3) = Np*Iph - Np*Io*(exp(((Vm/Ns)+(Im*Rs)/Np)/Vt) - 1) - Np*((((Vm/Ns)+((Im*Rs)/Np))/Rp)) - Im;
F(4) = (((Np/Ns*Vt)*Io*(exp((Vm + ((Im*Ns*Rs)/Np))/Ns*Vt)) + (1/(Ns*Rp)/Np))/(1 + (Rs*Vt)*Io*(exp((Vm + ((Im*Ns*Rs)/Np))/Ns*Vt)) + (Rs/Rp))) - (Im/Vm);
F(5) = (((-Np/Ns*Vt)*Io*(exp(Voc/Ns*Vt)) - (1/Ns*Rp/Np)) / (1 + (Rs/Vt)*Io*(exp(Voc/Ns*Vt)) + (Rs/Rp))) + 1/Rs;
disp(F)
end
But still i am receiving the same error:
>> fun = @solar5d;
>> x0 = [0,0,0,0];
>> x = fsolve(fun,x0)
-Inf NaN -Inf NaN NaN
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
> In fsolve (line 298) Error using levenbergMarquardt (line 16) Objective function is returning undefined values at initial point. fsolve cannot continue.
Error in fsolve (line 397) levenbergMarquardt(funfcn,x,verbosity,options,defaultopt,f,JAC,caller, ...
>>
And ? Did you change x0 to a vector without zeros ? No, you didn't.
Best wishes
Torsten.
I already did it but i am not receiving the correct values again.
I change my vector to x0 = [1,1,1,1,1];
Thanks for your help!!!!
So it works now, but you get an unexpected result ?
Best wishes
Torsten.
Yes i am not receiving the correct results i want.
These are the results i am receiving:
x =
0.7116 -0.0000 1.0583 0.8775 0.2934
For the last on its supposed to be 0.028 is the only one i can calculate manually but i am getting wrong results.
Matt J
Matt J on 24 Nov 2017
Edited: Matt J on 24 Nov 2017
If you know x(5) is supposed to be .028 why are you initializing with x(5)=1? For that matter, why are you doing the extra work of solving numerically for x(5) when you can get it analytically? It makes life easier for fsolve if you have fewer unknowns.
I wanted to calculate it but it self instead of define it. What i am trying to do is to include the simultaneous equations i mentioned above using the nonlinear equation solver 'fsolve', which is embedded with 'Levenberg-Marquardt and 'Gauss-Newton'
Did you check that fsolve converged at all? If so, if you plug the resulting x into solar5d the result should be a set of very small numbers. Solving a set of nonlinear equations is not always easy. In the general case, a solution may not even exist.
If you have some knowledge of what the solution should be, try with a starting vector close to this estimate. It may also be a good idea to double-check that your equations and parameters are all correct
Hello Are,
I have the solutions from a different source so i will try to get that solutions include them in the equations and see if i will get zero.
If i am getting zero that means the equations are correct i will try to doing it now and see. Thanks for your help :)

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!