5 equations in 5 unknowns with fsolve
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 25 de Dic. de 2021
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
Respuestas (3)
John D'Errico
el 24 de Dic. de 2021
Editada: John D'Errico
el 24 de Dic. de 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
el 25 de Dic. de 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 comentarios
Walter Roberson
el 25 de Dic. de 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)
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
Ver también
Categorías
Más información sobre Numbers and Precision en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!