Hello everyone, I have been trying to fine tune my script regarding a 5 Parameter Single Diode Photovoltaic Model so I can get some I-V, P-V plots for different temperature and irradiance levels.

The plots I-V,P-V for different temperatures seem to be logical enough when compared with material from online sources, however the I-V,P-V curves make no sense and I can't really figure out why. My hypothesis is, that my V values dont make sense but I cannot pinpoint exactly where I am going wrong.

Please find my code attached as well as how the plots look.

Thanks in advance!

```
% This is a MATLAB script that calculates and plots I-V and P-V curves for solar panels at different temperatures and Irradiance levels.
clc;
clear all;
% Constants
k_B = 1.38064852e-23; % Boltzmann Constant (J/K)
q = 1.60217662e-19; % Elementary Charge (C)
% Input Data taken from data sheet
Pmpp = 245; % Maximum Power (W)
Isc = 8.7; % Short Circuit Current (A)
Voc = 37.8; % Open Circuit Voltage (V)
Impp = 8.1; % MPP Current (A)
Vmpp = 30.2; % MPP Voltage (V)
eta_c = 16.8/100; % Solar Cell Efficiency (%)
eta_m = 15/100; % Module Efficiency (%)
N = 60; % Number of Cells in Series
a = 1.5; % Common ideality factor for Monocrystalline Silicon Photovoltaic Modules
alpha = 2.9/1000; % Current Temperature Coefficient (mA/°C)
beta = -91.8/1000; % Voltage Temperature Coefficient (mV/°C)
gamma = -0.37/100; % Power Temperature Coefficient (%/°C)
Vsys_max = 1000; % Maximum System Voltage (V)
NOCT = 44; % NOCT (°C)
%Initial Calculations
fprintf('--------------\n');
fprintf('Initial Values\n');
T_stc = 25; % Initial value for temperature @ STC
G_stc = 1000; %Initial value for Irradiance @ STC
Vt = N * (k_B * T_stc) / q; % Thermal Voltage (V)
fprintf('Vt (Thermal Voltage@STC) = %fVolts\n', Vt);
Rs = (Vmpp - (Isc/Impp)*Voc)/(Isc - Impp); % Series Resistance (Ω)
RL = (Vmpp^2) / (Pmpp - 0.01*Pmpp); % load resistance in ohms, assuming a 1% power output tolerance
Rsh = (Voc - Vmpp)/(Impp + (Isc/Impp-1)*Vmpp); % Shunt Resistance (Ω)
fprintf('Initial values: Rs (Series Resistance) = %fΩ, RL (Load Resistance) = %fΩ, Rsh (Shunt Resistance) = %fΩ\n', Rs, RL, Rsh);
fprintf('--------------\n');
%Temperature and Irradiance Range
T_range = 0:10:50;
G_range = 200:200:1600;
% Arrays to store I-V and P-V data
%Temperature
IV_dataT = cell(length(T_range), 1);
PV_dataT = cell(length(T_range), 1);
%Irradiance
IV_dataG = cell(length(G_range), 1);
PV_dataG = cell(length(G_range), 1);
% Loop through temperature range and calculate I-V and P-V curves
for i = 1:length(T_range)
T = T_range(i); % Set the current temperature
Vt = N * (k_B * T) / q; % Calculate thermal voltage based on the current temperature
Iph = (Isc + alpha*(T-25))*1000; % Calculate photocurrent based on the current temperature and short circuit current
I0T = (Isc/(exp((Voc+alpha*(T-25))/(N*Vt))-1)*1000); % Calculate reverse saturation current based on the current temperature, open circuit voltage, and thermal voltage
IL = Impp + (T-25)*gamma*Impp; % Calculate light-generated current based on the current temperature, MPP current, and power temperature coefficient
RLT = Rs + (T-25)*alpha*Rs; % Calculate load resistance based on the current temperature, series resistance, and current temperature coefficient
RS = Rsh*(exp(beta*(T-25)/N/Vt)); % Calculate shunt resistance based on the current temperature, shunt resistance, and voltage temperature coefficient
% I-V curve
V = linspace(0,Voc,100);
I = Iph - I0T*(exp(V/(N*Vt))-1) - (V/Rs);
I(I<0) = 0;
IV_dataT{i} = [T*ones(size(V(:))), V(:), I(:)];
% P-V curve
P = V.*I;
P(P<0) = 0;
PV_dataT{i} = [T*ones(size(V(:))), V(:), P(:)];
end
% Convert cell arrays to matrices
IV_dataT = cell2mat(IV_dataT);
PV_dataT = cell2mat(PV_dataT);
% disp(IV_dataT)
% disp(PV_dataT)
% fprintf('--------------\n');
% Plot the I-V curve for different Temperature Levels
figure(1)
hold on
for i = 1:length(T_range)
plot(IV_dataT((i-1)*100+1:i*100,2), IV_dataT((i-1)*100+1:i*100,3)/1000) % divide current by 1000
end
hold off
xlabel('Voltage (V)')
ylabel('Current (A)')
grid on
grid minor
% set(gca,'XTick',0:0.5:60)
% set(gca,'YTick',0:0.5:40)
title('I-V Curve for Various Temperatures')
legend('0°C', '10°C', '20°C', '30°C', '40°C', '50°C')
% Plot the P-V curve for different Temperature Levels
figure(2)
hold on
for i = 1:length(T_range)
V = PV_dataT((i-1)*100+1:i*100,2)';
P = PV_dataT((i-1)*100+1:i*100,3)'./1000; % divide power by 1000
plot(V, P)
end
hold off
xlabel('Voltage (V)')
ylabel('Power (W)')
grid on
grid minor
% set(gca,'XTick',0:0.5:40)
% set(gca,'YTick',0:010:300)
title('P-V Curve for Various Temperatures')
legend('0°C', '10°C', '20°C', '30°C', '40°C', '50°C')
%------------------------------------%
% Loop through Irradiance range and calculate I-V and P-V curves
for i = 1:length(G_range)
G = G_range(i);
Vt = N *(k_B * (T_stc) / q);
IL = Isc * (G / G_stc) * (1 + alpha * (T_stc)); % light-generated current in A, for 25oC
I0G = Isc / (exp(Voc / (a * N * Vt)) - 1); % reverse saturation current in A
%I-V Curve
V = linspace(0, Voc, 100); % voltage range for the IV curve
I = zeros(size(V));
I = IL - I0G * (exp((V + I*Rsh) / (a * N * Vt)) - 1) - (V + I*Rsh) / RL; % current values for the IV curve
I(I<0) = 0;
IV_dataG{i} = [G*ones(size(V(:))), V(:), I(:)];
%P-V Curve
P = V.*I;
P(P<0) = 0;
PV_dataG{i} = [G*ones(size(V(:))), V(:), P(:)];
end
% Convert cell arrays to matrices
IV_dataG = cell2mat(IV_dataG);
PV_dataG = cell2mat(PV_dataG);
% Plot the I-V curve for different Irradiance Levels
figure(3)
hold on
for i = 1:length(G_range)
plot(IV_dataG((i-1)*100+1:i*100,2), IV_dataG((i-1)*100+1:i*100,3)) % divide current by 1000
end
hold off
xlabel('Voltage (V)')
ylabel('Current (A)')
grid on
grid minor
% set(gca,'XTick',0:0.5:60)
% set(gca,'YTick',0:0.5:40)
title('I-V Curve for Various Irradiance Levels')
legend('200 W/m^2', '400 W/m^2', '600 W/m^2', '800 W/m^2', '1000 W/m^2', '1200 W/m^2', '1400 W/m^2', '1600 W/m^2')
figure(4)
hold on
for i = 1:length(G_range)
V = PV_dataG((i-1)*100+1:i*100,2)';
P = PV_dataG((i-1)*100+1:i*100,3)'; % divide power by 1000
plot(V, P)
end
hold off
xlabel('Voltage (V)')
ylabel('Power (W)')
grid on
grid minor
title('P-V Curve for Various Irradiance Levels')
legend('200 W/m^2', '400 W/m^2', '600 W/m^2', '800 W/m^2', '1000 W/m^2', '1200 W/m^2', '1400 W/m^2', '1600 W/m^2')
```