5 equations in 5 unknowns with fsolve

9 views (last 30 days)
M_Shaban
M_Shaban on 24 Dec 2021
Commented: M_Shaban on 25 Dec 2021
how to solve these equations with fsolve function or any function
and this my code:
clc
clear
close all
function main
P0 = rand(5,1);
P = fsolve(@myfun,P0);
end
function F = myfun(p)
Isc = p(1);
Iph = p(2);
Imp = p(3);
Vmp = p(4);
Rsh = p(5);
K = 1.38 * 10^-23;
T = 298;
q = 1.602 * 10^-19;
Ns = 12;
Voc = 21.7;
Isc = 3.45;
Imp = 3.15;
Vmp = 17.4;
F(1) = (Iph - Io*exp(((q/(A*K*T))*Isc*Rs) - 1) - ((Isc*Rs) / (Rsh))) - Isc;
F(2) = (Io*exp(((q/(A*K*T*Ns))*Voc) - 1) - ((Voc) / (Rsh*Ns))) - Iph;
F(3) = (Io*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs))) - 1) - ((Vmp+(Imp*Ns*Rs)) / (Rsh*Ns))) - Imp;
F(4) = ((Imp*((Io*(q/(A*K*T)*Rs*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs)))))) + (Rs/Rsh))) / ((Io*(q/(A*K*T*Ns)*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs)))))) + (1/(Rsh*Ns)))) - (Vmp) ;
F(5) = (((1+((Io*(q/(A*K*T)*Rs*exp(((q/(A*K*T))*(Isc*Rs))))) + (Rs/Rsh)))) / ((Io*(q/(A*K*T*Ns)*exp(((q/(A*K*T))*(Isc*Rs))))) - (1 / (Rsh*Ns)))) - (Rsh);
end
These equations
These known parameters
These unknown Parameters
  8 Comments

Sign in to comment.

Answers (3)

John D'Errico
John D'Errico on 24 Dec 2021
Edited: John D'Errico on 24 Dec 2021
Do you expect your function to do anything? LOOK AT YOUR CODE CAREFULLY. Read the code you wrote yourself. Too often, we forget to do that. It is easy to just assume that what we wrote is what we wanted to write.
function F = myfun(p)
Isc = p(1);
Iph = p(2);
Imp = p(3);
Vmp = p(4);
Rsh = p(5);
It starts as above. So Isc is the first unknown. Ok, No problem there.
But then what do you do IMMEDIATELY AFTERWARDS?
Ns = ;
That will simply cause an immediate syntax error.
And then we see these lines:
Isc = 3.45;
Imp = 3.15;
Vmp = 17.4;
So even though you pass in values for those variables, you immediately overwrite them as CONSTANTS. Maybe you put those lines in when you were debugging the code. Maybe not. But this objective function as written can not be used to solve anything.
The code you show will do nothing useful. It cannot.
It is possible that your real code is different from what we see. But what we see will not even execute, and even if you fixed the syntax error I pointed out, it will still never optimize those variables, because you are overwriting them inside the objective function.
Can I actually try to solve your problem? No. You do not show what is Ns. So I can go no further.

Torsten
Torsten on 25 Dec 2021
This code starts running although producing Inf and NaN values:
function main
P0 = rand(5,1);
P = fsolve(@myfun,P0)
end
function F = myfun(p)
Isc = p(1);
Iph = p(2);
Imp = p(3);
Vmp = p(4);
Rsh = p(5);
K = 1.38 * 10^-23;
T = 25;
q = 1.602 * 10^-19;
Ns = 12; % set since missing in your code
Voc = 21.7;
Io = 1.0; % set since missing in your code
A = 1.0; % set since missing in your code
Rs = 1.0; % set since missing in your code
F(1) = (Iph - Io*exp(((q/(A*K*T))*Isc*Rs) - 1) - ((Isc*Rs) / (Rsh))) - Isc;
F(2) = (Io*exp(((q/(A*K*T*Ns))*Voc) - 1) - ((Voc) / (Rsh*Ns))) - Iph;
F(3) = (Io*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs))) - 1) - ((Vmp+(Imp*Ns*Rs)) / (Rsh*Ns))) - Imp;
F(4) = ((Imp*((Io*(q/(A*K*T)*Rs*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs)))))) + (Rs/Rsh))) / ((Io*(q/(A*K*T*Ns)*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs)))))) + (1/(Rsh*Ns)))) - (Vmp) ;
F(5) = (((1+((Io*(q/(A*K*T)*Rs*exp(((q/(A*K*T))*(Isc*Rs))))) + (Rs/Rsh)))) / ((Io*(q/(A*K*T*Ns)*exp(((q/(A*K*T))*(Isc*Rs))))) - (1 / (Rsh*Ns)))) - (Rsh);
end
  3 Comments

Sign in to comment.


Walter Roberson
Walter Roberson on 25 Dec 2021
This is not the only solution.
format long g
p0 = rand(6,1);
Isc = 3.45;
Imp = 3.15;
Vmp = 17.4;
p0(1) = Isc;
p0(3) = Imp;
p0(4) = Vmp;
P = fsolve(@myfun, p0)
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
No solution found. fsolve stopped because the last step was ineffective. However, the vector of function values is not near zero, as measured by the value of the function tolerance.
P = 6×1
2.05488354263412 2.07231772577932 81.604849760093 14.1285080468827 -0.00260376090944614 0.0135113004526667
function F = myfun(p)
Isc = p(1);
Iph = p(2);
Imp = p(3);
Vmp = p(4);
Rsh = p(5);
K = 1.38 * 10^-23;
T = 25+273;
q = 1.602 * 10^-19;
Ns = 12;
Voc = 21.7;
Io = 5.5118e-6;
A = 1.7571;
Rs = 2.9e-3;
F(1) = (Iph - Io*exp(((q/(A*K*T))*Isc*Rs) - 1) - ((Isc*Rs) / (Rsh))) - Isc;
F(2) = (Io*exp(((q/(A*K*T*Ns))*Voc) - 1) - ((Voc) / (Rsh*Ns))) - Iph;
F(3) = (Io*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs))) - 1) - ((Vmp+(Imp*Ns*Rs)) / (Rsh*Ns))) - Imp;
F(4) = ((Imp*((Io*(q/(A*K*T)*Rs*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs)))))) + (Rs/Rsh))) / ((Io*(q/(A*K*T*Ns)*exp(((q/(A*K*T*Ns))*(Vmp+(Imp*Ns*Rs)))))) + (1/(Rsh*Ns)))) - (Vmp) ;
F(5) = (((1+((Io*(q/(A*K*T)*Rs*exp(((q/(A*K*T))*(Isc*Rs))))) + (Rs/Rsh)))) / ((Io*(q/(A*K*T*Ns)*exp(((q/(A*K*T))*(Isc*Rs))))) - (1 / (Rsh*Ns)))) - (Rsh);
end

Community Treasure Hunt

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

Start Hunting!

Translated by