Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. import math
  2.  
  3. def calculate_current(I, Vs, R, Is, n, Vt):
  4.     return (Vs - n*Vt*math.log((I + Is)/Is)) / R
  5.  
  6. def calculate_Vd(I, Is, n, Vt):
  7.     return n*Vt*math.log((I + Is)/Is)
  8.    
  9. def run_iteration(Vs, R, Is, n, Vt = 25.85):
  10.     i = 0
  11.     initial_current = Vs / R
  12.     while (i < 10):
  13.         current_val = calculate_current(initial_current, Vs, R, Is, n, Vt)
  14.         voltageD_val = calculate_Vd(initial_current, Is, n, Vt)
  15.         i += 1
  16.     return current_val, voltageD_val
  17.    
  18. Vs, R, Is, n = 10, 1, 20, 1.95
  19. answers = run_iteration(Vs, R, Is, n)
  20. print("With values for Vs, R, Is, and n being respectively:  ", Vs, R, Is, n)
  21. print("The approximate value of the current and voltage is respectively: ")
  22. print("I = ", answers[0],"Vd = ", answers[1])
  23.  
  24. Vs, R, Is, n = 5, 2.2, 20, 1.95
  25. answers = run_iteration(Vs, R, Is, n)
  26. print("With values for Vs, R, Is, and n being respectively:  ", Vs, R, Is, n)
  27. print("The approximate value of the current and voltage is respectively: ")
  28. print("I = ", answers[0],"Vd = ", answers[1])
  29.  
  30. Vs, R, Is, n = 2.5, 2.2, 20, 1.95
  31. answers = run_iteration(Vs, R, Is, n)
  32. print("With values for Vs, R, Is, and n being respectively:  ", Vs, R, Is, n)
  33. print("The approximate value of the current and voltage is respectively: ")
  34. print("I = ", answers[0],"Vd = ", answers[1])
  35.  
  36. Vs, R, Is, n = 15, 10, 35, 1.95
  37. answers = run_iteration(Vs, R, Is, n)
  38. print("With values for Vs, R, Is, and n being respectively:  ", Vs, R, Is, n)
  39. print("The approximate value of the current and voltage is respectively: ")
  40. print("I = ", answers[0],"Vd = ", answers[1])
  41.  
  42. Vs, R, Is, n = 3, 10, 35, 1.95
  43. answers = run_iteration(Vs, R, Is, n)
  44. print("With values for Vs, R, Is, and n being respectively:  ", Vs, R, Is, n)
  45. print("The approximate value of the current and voltage is respectively: ")
  46. print("I = ", answers[0],"Vd = ", answers[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement