Hier de code voor -10°C. De analytische uitdrukking voor de spanning in functie van de stroom zit meer vervat in de code.
Code: Selecteer alles
import numpy as np
from scipy.optimize import fsolve
import matplotlib.pyplot as plt
n=9/5
I0=10e-9
q=1.602e-19
k=1.380649e-23
T=273.15-10
a=q/(k*T)
R=5
# Define the nonlinear function f(i, t)
def f(i, t):
return 2*np.sin(2*np.pi*t)-R*i-np.log(i/I0+1)*n/a
def solve_for_i(t, initial_guess=0.0001):
# Define a wrapper function that fixes t
def equation_to_solve(i):
return f(i, t)
# Use root_scalar to solve the equation
solution = fsolve(equation_to_solve, 0.001)
return solution[0]
def calculate_v_diode_from_i(i):
return np.log(i/I0+1)*n/a
def i_of_t(t_values):
return [solve_for_i(t) for t in t_values]
def v_bron_of_t(t_values):
return [2*np.sin(2*np.pi*t) for t in t_values]
def v_of_i(i_values):
return [calculate_v_diode_from_i(i) for i in i_values]
t_values = np.arange(0, 2, 0.001) # Example t values
i_values = i_of_t(t_values)
v_values = v_of_i(i_values)
v_bron_values = v_bron_of_t(t_values)
# Plot the function i(t)
plt.plot(t_values, i_values, label="i(t)")
plt.plot(t_values, v_values, label="v(t)")
plt.plot(t_values, v_bron_values, label="v_bron(t)")
plt.xlabel("t")
plt.legend()
plt.title("T = -10°C")
plt.grid(True)
plt.show()