Created
January 9, 2024 14:59
-
-
Save Arxcis/7a2ac12ec826309b0d711f5c5b5666ba to your computer and use it in GitHub Desktop.
TSE2220-øving-uke2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from numpy import arange, pi, e | |
from matplotlib.widgets import Slider | |
# Initial values | |
V_0 = 40 # volt | |
f = 50 # hz | |
R = 10 # Ohm | |
L = 10 # henry | |
def make_Tau(L=L,R=R): | |
return L / R | |
def make_Omega(f=f): | |
return 2 * pi * f | |
I_max = V_0 / R # Ampere | |
SAMPLE_TIME = 10 | |
SAMPLE_RATE = .1 | |
def f(t, I_max, T): | |
return I_max * (1 - e**(-t/T)) | |
# Plot initial | |
fig, ax = plt.subplots() | |
t = arange(0, SAMPLE_TIME, SAMPLE_RATE) | |
v_t = f(t, I_max, make_Tau()) | |
line, = ax.plot(t, v_t) | |
fig.subplots_adjust(left=0.25, bottom=0.25) | |
# Resistans slider | |
ax_ohm = fig.add_axes([0.25, 0.05, 0.65, 0.03]) | |
ohm_slider = Slider( | |
ax=ax_ohm, | |
label='R [Ohm]', | |
valmin=1, | |
valmax=50, | |
valinit=10, | |
) | |
def update_resistance(val): | |
global R, I_max | |
R = val | |
I_max = V_0 / val | |
line.set_ydata(f(t, I_max, make_Tau(R=val, L=L))) | |
fig.canvas.draw_idle() | |
ohm_slider.on_changed(update_resistance) | |
# Induktans slider | |
ax_inductance = fig.add_axes([0.25, 0.11, 0.65, 0.03]) | |
inductance_slider = Slider( | |
ax=ax_inductance, | |
label='L [H]', | |
valmin=1, | |
valmax=60, | |
valinit=10, | |
) | |
def update_inductance(val): | |
global L | |
L = val | |
line.set_ydata(f(t, I_max, make_Tau(R=R, L=val))) | |
fig.canvas.draw_idle() | |
inductance_slider.on_changed(update_inductance) | |
# Show | |
ax.set_xlabel("t [s]") | |
ax.set_ylabel("i [A]") | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment