5 equations in 5 unknowns with fsolve
15 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2021-12-25
syms p [1 5]
eqn = myfun(p).'
sol = solve(eqn)
function F = myfun(p)
Isc = p(1);
Iph = p(2);
Imp = p(3);
Vmp = p(4);
Rsh = p(5);
K = sym(1.38) * 10^-23;
T = sym(25+273);
q = sym(1.602) * 10^-19;
Ns = sym(12);
Voc = sym(21.7);
%Isc = sym(3.45);
%Imp = sym(3.15);
%Vmp = sym(17.4);
Io = sym(5.5118e-6);
A = sym(1.7571);
Rs = sym(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
回答(3 个)
John D'Errico
2021-12-24
编辑:John D'Errico
2021-12-24
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
2021-12-25
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 个评论
Walter Roberson
2021-12-25
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)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numbers and Precision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!