Problem in getting correct output for double diode model of pv array

조회 수: 11 (최근 30일)
Aryan Sharma
Aryan Sharma 2023년 5월 18일
답변: Giulio Mangherini 2024년 10월 11일
the following is the code for solving current equation of a double diode model of a pv array, it throws an error when I run it
% Parameters
I_L = 8.3; % Light-generated current
I_01 = 1.22e-12; % Reverse saturation current for diode 1
I_02 = 1.22e-12; % Reverse saturation current for diode 2
n_1 = 1.36; % Ideality factor for diode 1
n_2 = 2.34; % Ideality factor for diode 2
k = 1.380649e-23; % Boltzmann constant
q = 1.60217662e-19; % Electronic charge
T = 298.15; % Temperature
R_S = 0.221; % Series resistance
% Voltage range
V_min = 0;
V_max = 32.9;
V_step = 0.01;
V = V_min:V_step:V_max;
% Double diode model
I = zeros(size(V));
for i = 1:length(V)
f = @(x) I_L - I_01*(exp(q*(V(i)+x*R_S)/(n_1*k*T))-1) - I_02*(exp(q*(V(i)+x*R_S)/(n_2*k*T))-1) - x/R_S;
I(i) = fsolve(f, 33);
end
% Plot current vs voltage
figure;
plot(V,I);
xlabel('Voltage (V)');
ylabel('Current (A)');
title('Double Diode Model');
  댓글 수: 5
Joel Van Sickel
Joel Van Sickel 2023년 5월 22일
It's likely your equation for fsolve is incorrect, can you share the analytical formula that you are tryint to solve?
Aryan Sharma
Aryan Sharma 2023년 5월 25일
The equations used in the code are as follows:
  • Equation (1): Light-generated current (IL):
  • IL = I_L - I_01 * (exp(q * (V(i) + x * R_S) / (n_1 * k * T)) - 1) - I_02 * (exp(q * (V(i) + x * R_S) / (n_2 * k * T)) - 1)
  • Equation (2): Diode current for diode 1 (ID1):
  • ID1 = I_01 * (exp(q * (V(i) + x * R_S) / (n_1 * k * T)) - 1)
  • Equation (3): Diode current for diode 2 (ID2):
  • ID2 = I_02 * (exp(q * (V(i) + x * R_S) / (n_2 * k * T)) - 1)
  • Equation (4): Equation to solve for the current (I) at each voltage point:
  • f = @(x) I_L - I_01 * (exp(q * (V(i) + x * R_S) / (n_1 * k * T)) - 1) - I_02 * (exp(q * (V(i) + x * R_S) / (n_2 * k * T)) - 1) - x / R_S
These equations model the behavior of the double-diode photovoltaic module and are used to calculate the current (I) at different voltage (V) points within the specified range. The fsolve function is utilized to numerically solve the equation (4) and obtain the corresponding current values.

댓글을 달려면 로그인하십시오.

답변 (2개)

Sayan
Sayan 2023년 9월 7일
I understand from your issue that the code you are trying to run to obtain the "I-V" characteristics of a PV cell array is throwing an error. Below are the possible workarounds for the issue:
  • The number of function evaluations can be increased for the "fsolve" function to overcome the error.
  • The initial condition to determine the value of current "I" defined in the "fsolve" function can be provided to the previous computed value of current rather than hard coding it to 33.
  • The last term in the function handle expression "f" should be dictating the current through the shunt resistance. But shunt resistance is not declared in the code, and the expression "x/R_s" is wrong.
  • The changes are shown in the below-mentioned code snippet. The code mentioned below should be included after the line "I = zeros(size(V));"
%declare the value of shunt resistance
R_sh=100;%say 100
%compute the initial value of current for 0 voltage
f1 = @(x) I_L - I_01*(exp(q*(x*R_S)/(n_1*k*T))-1) - I_02*(exp(q*(x*R_S)/(n_2*k*T))-1) - x*R_S/R_sh;
I(1)=fsolve(f1,0);
%declare the number of function evaluations for "fsolve" function
options = optimoptions('fsolve', 'MaxFunctionEvaluations', 1000);
for i = 2:length(V)
f = @(x) I_L - I_01*(exp(q*(V(i)+x*R_S)/(n_1*k*T))-1) - I_02*(exp(q*(V(i)+x*R_S)/(n_2*k*T))-1) - x*R_S/R_sh;%declare x*R_S/R_sh as the current through shunt branch
I(i) = fsolve(f,I(i-1),options);%provide the "options" to "fsolve" function call
end
%now plot the I-V data and change the value of the constants to meet the
%required curve
Further information on "fsolve" function can be found in the following documentation.
Hope this helps in resolving the issue.

Giulio Mangherini
Giulio Mangherini 2024년 10월 11일
Hi,
I'm trying to fit an I-V curve (data attached as .txt) from a scientific article using a 2-diode model, but I'm running into some issues with my MATLAB code.
% Load data
data = load('C:\Users\Standard\Downloads\IV_curve_prova.txt'); % Load the provided file
V = data(:, 1); % Voltage (first column)
I_measured = data(:, 2); % Current (second column)
% Constants
q = 1.602176634e-19; % Charge of an electron (Coulombs)
k = 1.380649e-23; % Boltzmann constant (Joule/Kelvin)
T = 298.15; % Temperature in Kelvin (adjust if needed)
% Define the two-diode model function
twoDiodeModel = @(params, V) ...
params(1) - ... % I_ph
params(2) * (exp(q*(V + params(5)*I_measured)/(params(3)*k*T)) - 1) - ... % First diode current
params(4) * (exp(q*(V + params(5)*I_measured)/(params(6)*k*T)) - 1) - ... % Second diode current
(V + params(5)*I_measured)/params(7); % Shunt current (ohmic losses)
% Initial guesses for parameters [I_ph, I_01, n1, I_02, Rs, n2, Rsh]
initial_guess = [1e-3, 1e-12, 1.05, 1e-12, 0.01, 2.05, 110]; % Adjust these as needed
% Define lower and upper bounds for parameters
lower_bounds = [0, 0, 1, 0, 0, 2, 100]; % Lower bounds for [I_ph, I_01, n1, I_02, Rs, n2, Rsh]
upper_bounds = [1e-2, 2, 1.1, 2, 0.1, 2.1, 200]; % Upper bounds for [I_ph, I_01, n1, I_02, Rs, n2, Rsh]
% Perform nonlinear least-squares fitting with bounds
options = optimset('Display', 'iter', 'TolFun', 1e-9, 'TolX', 1e-9);
[params_fit, resnorm] = lsqcurvefit(twoDiodeModel, initial_guess, V, I_measured, lower_bounds, upper_bounds, options);
% Extract fitted parameters
I_ph_fit = params_fit(1);
I_01_fit = params_fit(2);
n1_fit = params_fit(3);
I_02_fit = params_fit(4);
Rs_fit = params_fit(5);
n2_fit = params_fit(6);
Rsh_fit = params_fit(7);
% Display the fitted parameters
fprintf('Fitted Parameters:\n');
fprintf('I_ph = %e\n', I_ph_fit);
fprintf('I_01 = %e\n', I_01_fit);
fprintf('n1 = %f\n', n1_fit);
fprintf('I_02 = %e\n', I_02_fit);
fprintf('R_s = %f Ohms\n', Rs_fit);
fprintf('n2 = %f\n', n2_fit);
fprintf('R_sh = %f Ohms\n', Rsh_fit);
% Plot the fitted curve against the measured data
I_fitted = twoDiodeModel(params_fit, V);
figure;
plot(V, I_measured, 'ro', 'DisplayName', 'Measured Data');
hold on;
plot(V, I_fitted, 'b-', 'DisplayName', 'Fitted Curve');
xlabel('Voltage (V)');
ylabel('Current (I)');
legend('show');
grid on;
title('Two-Diode Model Fitting');
Initially, I did not define any bounds for my parameters. The code ran, but the resulting curve did not fit my data. After defining the bounds, I get this error: "Sum of squared function values at initial point is Inf or NaN. lsqcurvefit cannot continue."
I'd appreciate any help or advice on how to fit this curve.
Thanks in advance for your assistance!
Best regards,
Giulio

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by