I am trying to solve a set of equation which is consist of five equations. Here is the function file:
function [f1, f2, f3, f4, f5] = myfun(a1, a2, a3, a4, a5, x1, x2, x3, x4, x5)
f1 = x1-x2*(exp((x4*a1)/(x3*a5))-1)-((x4*a1)/x5)-a1;
f2 = x2*(exp(a2/(x3*a5))-1)+(a2/x5)-x1;
f3 = x1-x2*(exp((a3+x4*a4)/(x3*a5))-1)-((a3+x4*a4)/x5)-a4;
f4 = a3*(((x2/(x3*a5))*exp((a3+x4*a4)/(x3*a5))+(1/x5))/(1+((x4*x2)/(x3*a5))*exp((a3+x4*a4)/(x3*a5))+(x4/x5)))-a4;
f5 = (((x2/(x3*a5))*exp((x4*a1)/(x3*a5))+(1/x5))/(1+((x4*a1)/(x3*a5))*exp((x4*a1)/(x3*a5))+(x4/x5)))-(1/x5);
end
This is the main code:
% Sabit degerler
k = 1.38e-23; % Boltzman sabiti
q = 1.602e-19; % Elektronun yuku
T = 25+273; % Sicaklik (K)
Ns = 36; % Hucre Sayisi
a1 = 2.4; % Isc
a2 = 21.8; % Voc
a3 = 17.2; % Vmpp
a4 = 2.20; % Impp
a5 = (Ns*k*T)/q; % Vt
%Is0 = (a1+Ki*dt)/(exp((a2+Kv*dt)/(x3*a5))-1);
x0 = [2.4, 1.2e-7, 1.5, 0.5, 600];
lb = [2, 1e-7, 1.3, 0.3, 400];
ub = [2.6, 5e-7, 1.7, 0.7, 900];
x = lsqnonlin(@myfun, x0, lb, ub);
I saved function file as a "myfun.m" and both of the files are in the same directory. When I run the main code it gives this error expression:
"Not enough input arguments.
Error in myfun (line 2)
f1 = x1-x2*(exp((x4*a1)/(x3*a5))-1)-((x4*a1)/x5)-a1;
Error in lsqnonlin (line 206)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in mohapatra (line 17)
x = lsqnonlin(@myfun, x0, lb, ub);
Caused by:
Failure in initial objective function evaluation. LSQNONLIN cannot continue."

 Réponse acceptée

Stephan
Stephan le 21 Mar 2019
Modifié(e) : Stephan le 21 Mar 2019

0 votes

Hi,
try:
% Sabit degerler
k = 1.38e-23; % Boltzman sabiti
q = 1.602e-19; % Elektronun yuku
T = 25+273; % Sicaklik (K)
Ns = 36; % Hucre Sayisi
a1 = 2.4; % Isc
a2 = 21.8; % Voc
a3 = 17.2; % Vmpp
a4 = 2.20; % Impp
a5 = (Ns*k*T)/q; % Vt
%Is0 = (a1+Ki*dt)/(exp((a2+Kv*dt)/(x3*a5))-1);
x0 = [2.4, 1.2e-7, 1.5, 0.5, 600];
lb = [2, 1e-7, 1.3, 0.3, 400];
ub = [2.6, 5e-7, 1.7, 0.7, 900];
x = lsqnonlin(@(x)myfun(x, a1, a2, a3, a4, a5), x0, lb, ub);
function f = myfun(x, a1, a2, a3, a4, a5)
x1 = x(1);
x2 = x(2);
x3 = x(3);
x4 = x(4);
x5 = x(5);
f(1) = x1-x2*(exp((x4*a1)/(x3*a5))-1)-((x4*a1)/x5)-a1;
f(2) = x2*(exp(a2/(x3*a5))-1)+(a2/x5)-x1;
f(3) = x1-x2*(exp((a3+x4*a4)/(x3*a5))-1)-((a3+x4*a4)/x5)-a4;
f(4) = a3*(((x2/(x3*a5))*exp((a3+x4*a4)/(x3*a5))+(1/x5))/(1+((x4*x2)/(x3*a5))*exp((a3+x4*a4)/(x3*a5))+(x4/x5)))-a4;
f(5) = (((x2/(x3*a5))*exp((x4*a1)/(x3*a5))+(1/x5))/(1+((x4*a1)/(x3*a5))*exp((x4*a1)/(x3*a5))+(x4/x5)))-(1/x5);
end
Best regards
Stephan

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics and Optimization dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by