Subscript indices must either be real positive integers or logicals.

1 回表示 (過去 30 日間)
Joanan Destin
Joanan Destin 2020 年 11 月 4 日
コメント済み: Joanan Destin 2020 年 11 月 5 日
I was trying to use the Newton–Raphson method to do it but I keep getting this error code ''Subscript indices must either be real positive integers or logicals.''
I have attached the data provided to me and the flowchart I was following to get this program.
clc
close all
clear
% Data provided
load('SD_Test_Data_01.mat', 'voltage')
load('SD_Test_Data_01.mat', 'current')
I = current;
V = voltage;
P = I.*V; % To find the P-V curve
Pmaxcurve = max(P);
% Graphs
figure(1);
plot (V, I,'b:')
xlabel('Voltage (V)'), ylabel('Current (A)')
title('I-V Curve')
figure(2);
plot(V, P,'r--');
xlabel('Voltage(V)'), ylabel('Power (W)')
title('P-V Curve')
figure(3);
plot (V, I,'--')
title('Combine Plots')
hold on
plot(V, P, 'r:');
hold off
%At the standard test conditions (STC)
[Pmax, index_of_Pmax] = max(P);
Imp = I(index_of_Pmax); %(A)
Vmp = V(index_of_Pmax); %(v)
%We know that
Isc = max(I); %(A)
Voc = max(V); %(V)
q = 1.6022e-19; %q is the electron charge
k = 1.3806e-23; % k is the Boltzmann constant in (J/k)
% if the solar cells inside a solar module reach 65?C
T = 25; % T the module temperature in celcius
% Initializing Rs the series resistance and the shunt resistance Rsh and n
Rsh = (Vmp/(Isc- Imp))- ((Voc-Vmp)/Imp);
Rs = 0;
n= 1.2;
% Taking an assumption that Rsh>>Vo
I0 = Isc/(exp(1)*(q(Voc/(n*k*T)))-1);
Nmax = 100; %maximum number of interations
g(1) = 0.5; %first approximation
for a = zeros(1, Nmax-1)
g(a+1) = g(a) - (Isc-I0(exp(q((Vmp+Imp*Rs)/n))-1) - ((Vmp+(Imp*Rs))/n*k*T)) / (-I0((q/(nkT))*(1+diff(I, V)*Rs)*exp(1)*(q(V+(I*Rs)/(nkT)))))-(1/Rsh)*(1 + diff(I, V)*Rs);
end
plot(g, 'r.')

採用された回答

James Tursa
James Tursa 2020 年 11 月 4 日
編集済み: James Tursa 2020 年 11 月 4 日
This line produces indexes of zeros:
for a = zeros(1, Nmax-1)
I think you meant this instead:
g = zeros(1, Nmax);
for a = 1:Nmax-1
Also, I would assume everywhere you have I0( you meant I0*(
Same comment for q( probably meant q*(
  1 件のコメント
Joanan Destin
Joanan Destin 2020 年 11 月 5 日
I followed your advice and now I got this error
% %
Error using diff
Difference order N must be a positive integer scalar.
Error in Esram (line 56)
g(a+1) = g(a) - (Isc-I0*(exp(1)*(q*((Vmp+(Imp*Rs))/n))-1) - ((Vmp+(Imp*Rs))/(n*k*T))) / (-I0*((q/(n*k*T))*(1 + diff(I, V)*Rs)*exp(1)*(q*(V+(I*Rs)/(n*k*T)))))-(1/Rsh)*(1 + diff(I, V)*Rs);
here is the updated program
clc
close all
clear
% Data provided
load('SD_Test_Data_01.mat', 'voltage')
load('SD_Test_Data_01.mat', 'current')
I = current;
V = voltage;
P = I.*V; % To find the P-V curve
Pmaxcurve = max(P);
% Graphs
figure(1);
plot (V, I,'b:')
xlabel('Voltage (V)'), ylabel('Current (A)')
title('I-V Curve')
figure(2);
plot(V, P,'r--');
xlabel('Voltage(V)'), ylabel('Power (W)')
title('P-V Curve')
figure(3);
plot (V, I,'--')
title('Combine Plots')
hold on
plot(V, P, 'r:');
hold off
%At the standard test conditions (STC)
[Pmax, index_of_Pmax] = max(P);
Imp = I(index_of_Pmax); %(A)
Vmp = V(index_of_Pmax); %(v)
%We know that
Isc = max(I); %(A)
Voc = max(V); %(V)
q = 1.6022e-19; %q is the electron charge
k = 1.3806e-23; % k is the Boltzmann constant in (J/k)
% if the solar cells inside a solar module reach 65?C
T = 25; % T the module temperature in celcius
% Initializing Rs the series resistance and the shunt resistance Rsh and n
Rsh = (Vmp/(Isc- Imp))- ((Voc-Vmp)/Imp);
Rs = 0;
n= 1.2;
% Taking an assumption that Rsh>>Vo
I0 = Isc/(exp(1)*(q*(Voc/(n*k*T)))-1);
Nmax = 1000; %maximum number of interations
g(1) = 0.5; %first approximation
g = zeros(1, Nmax);
for a = 1:Nmax-1
g(a+1) = g(a) - (Isc-I0*(exp(1)*(q*((Vmp+(Imp*Rs))/n))-1) - ((Vmp+(Imp*Rs))/(n*k*T))) / (-I0*((q/(n*k*T))*(1 + diff(I, V)*Rs)*exp(1)*(q*(V+(I*Rs)/(n*k*T)))))-(1/Rsh)*(1 + diff(I, V)*Rs);
end
plot(g, 'r.')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by