Why am I getting the error "Too many output arguments"?

조회 수: 2 (최근 30일)
Aftab Mohammed
Aftab Mohammed 2024년 3월 3일
답변: Walter Roberson 2024년 3월 3일
%initialise paramteres
A = 1.7;
k = 1.380658*(10^-23);
q = 1.6 * (10^-19);
Eg = 1.1;
Ior = 19.9693*(10^-6);
Iscr = 3.3;
ki = 1.7 * (10^-3);
ns = 40;
np = 2;
Rs = 5*(10^-5);
Rp = 5*(10^5);
Tr = 301.18;
Ta = 25;
%array error = 1;
amb = [25 40 60];
irr = [0.3 0.5 1];
%Evaluate
hold on
for i=1:3
Ipv = [];
Vpv = [];
Ppv = [];
G= irr(i);
Tc = Ta + (0.2*G) + 273.18;
Isc = (Iscr + ki*(Tc-Tr))*G;
Is = Ior * ((Tc/Tr)^3) * exp(q*Eg*(1/Tr-1/Tc)/(k*A));
I = Isc;
V = 0;
while I>0
while error>0.0001
f1= I-(np*Isc)+(np*Is)*(exp(q*((V/ns)+(I*Rs/np))/(A*k*Tc))-1)+(((V*np/ns)+(I*Rs))/(Rp));
df1= 1+(Rs/Rp)+((q*Is*Rs)/(A*k*Tc))*(exp(q*((V/ns)+(I*Rs/np))/(A*k*Tc)));
I= I-(f1/df1);
error=abs(f1/df1);
end
Ipv= [Ipv I];
Vpv = [Vpv V];
Ppv= [Ppv I*V];
V = V+0.1;
error = 1;
end
plot(Vpv, Ipv);
% plot(Vpv, Ppv);
end
Error using error
Too many output arguments.

채택된 답변

the cyclist
the cyclist 2024년 3월 3일
You are confusing MATLAB by using error (a MATLAB function) as a variable name.
I changed that variable name to errorVal, and initialized it to -Inf.
%initialise paramteres
A = 1.7;
k = 1.380658*(10^-23);
q = 1.6 * (10^-19);
Eg = 1.1;
Ior = 19.9693*(10^-6);
Iscr = 3.3;
ki = 1.7 * (10^-3);
ns = 40;
np = 2;
Rs = 5*(10^-5);
Rp = 5*(10^5);
Tr = 301.18;
Ta = 25;
%array error = 1;
amb = [25 40 60];
irr = [0.3 0.5 1];
%Evaluate
errorVal = -Inf;
hold on
for i=1:3
Ipv = [];
Vpv = [];
Ppv = [];
G= irr(i);
Tc = Ta + (0.2*G) + 273.18;
Isc = (Iscr + ki*(Tc-Tr))*G;
Is = Ior * ((Tc/Tr)^3) * exp(q*Eg*(1/Tr-1/Tc)/(k*A));
I = Isc;
V = 0;
while I>0
while errorVal>0.0001
f1= I-(np*Isc)+(np*Is)*(exp(q*((V/ns)+(I*Rs/np))/(A*k*Tc))-1)+(((V*np/ns)+(I*Rs))/(Rp));
df1= 1+(Rs/Rp)+((q*Is*Rs)/(A*k*Tc))*(exp(q*((V/ns)+(I*Rs/np))/(A*k*Tc)));
I= I-(f1/df1);
errorVal=abs(f1/df1);
end
Ipv= [Ipv I];
Vpv = [Vpv V];
Ppv= [Ppv I*V];
V = V+0.1;
errorVal = 1;
end
plot(Vpv, Ipv);
% plot(Vpv, Ppv);
end

추가 답변 (2개)

Torsten
Torsten 2024년 3월 3일
편집: Torsten 2024년 3월 3일
You don't initialize "error" in your code by giving it a value before you use it in the while loop.
That's why MATLAB assumes error to be the built-in "error" command:

Walter Roberson
Walter Roberson 2024년 3월 3일
You do not initialize error before you use it.
error happens to be the name of an important Mathworks function -- a function that is not permitted to return a value and so cannot exist in a form
while error>0.0001
Best would be if you used a different variable name (and made sure to initialize it). Compromise would be if you assigned to error before you use it.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by