import numpy as np
import matplotlib.pyplot as plt
# Constants
k = 1.380649e-23 # Boltzmann's constant (J/K)
q = 1.602176634e-19 # Charge of an electron (C)
T = 300 # Temperature in Kelvin
# Solar cell parameters
I_ph = 0.02 # Photo-generated current (A)
I_s1 = 1e-12 # Saturation current of diode 1 (A)
I_s2 = 1e-13 # Saturation current of diode 2 (A)
n1 = 1 # Ideality factor of diode 1
n2 = 2 # Ideality factor of diode 2
R_s = 0.001 # Series resistance (Ohms)
R_sh = 1000 # Shunt resistance (Ohms)
# Voltage range for I-V curve
V = np.linspace(0, 0.7, num=1000)
def two_diode_model(V, I_ph, I_s1, I_s2, n1, n2, R_s, R_sh, T):
V_T = k * T / q
I = np.zeros_like(V)
for i in range(len(V)):
v = V[i]
I[i] = I_ph - (I_s1 * (np.exp((v + I[i] * R_s) / (n1 * V_T)) - 1) +
I_s2 * (np.exp((v + I[i] * R_s) / (n2 * V_T)) - 1) +
(v + I[i] * R_s) / R_sh)
return I
I = two_diode_model(V, I_ph, I_s1, I_s2, n1, n2, R_s, R_sh, T)
# Plotting the I-V curve
plt.figure()
plt.plot(V, I)
plt.xlabel('Voltage (V)')
plt.ylabel('Current (A)')
plt.title('I-V Characteristic Curve of a Solar Cell (Two-Diode Model)')
plt.grid(True)
plt.show()