Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def calculate_current(I, Vs, R, Is, n, Vt):
- return (Vs - n*Vt*math.log((I + Is)/Is)) / R
- def calculate_Vd(I, Is, n, Vt):
- return n*Vt*math.log((I + Is)/Is)
- def run_iteration(Vs, R, Is, n, Vt = 25.85):
- i = 0
- initial_current = Vs / R
- while (i < 10):
- current_val = calculate_current(initial_current, Vs, R, Is, n, Vt)
- voltageD_val = calculate_Vd(initial_current, Is, n, Vt)
- i += 1
- return current_val, voltageD_val
- Vs, R, Is, n = 10, 1, 20, 1.95
- answers = run_iteration(Vs, R, Is, n)
- print("With values for Vs, R, Is, and n being respectively: ", Vs, R, Is, n)
- print("The approximate value of the current and voltage is respectively: ")
- print("I = ", answers[0],"Vd = ", answers[1])
- Vs, R, Is, n = 5, 2.2, 20, 1.95
- answers = run_iteration(Vs, R, Is, n)
- print("With values for Vs, R, Is, and n being respectively: ", Vs, R, Is, n)
- print("The approximate value of the current and voltage is respectively: ")
- print("I = ", answers[0],"Vd = ", answers[1])
- Vs, R, Is, n = 2.5, 2.2, 20, 1.95
- answers = run_iteration(Vs, R, Is, n)
- print("With values for Vs, R, Is, and n being respectively: ", Vs, R, Is, n)
- print("The approximate value of the current and voltage is respectively: ")
- print("I = ", answers[0],"Vd = ", answers[1])
- Vs, R, Is, n = 15, 10, 35, 1.95
- answers = run_iteration(Vs, R, Is, n)
- print("With values for Vs, R, Is, and n being respectively: ", Vs, R, Is, n)
- print("The approximate value of the current and voltage is respectively: ")
- print("I = ", answers[0],"Vd = ", answers[1])
- Vs, R, Is, n = 3, 10, 35, 1.95
- answers = run_iteration(Vs, R, Is, n)
- print("With values for Vs, R, Is, and n being respectively: ", Vs, R, Is, n)
- print("The approximate value of the current and voltage is respectively: ")
- print("I = ", answers[0],"Vd = ", answers[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement