Reputation: 23
I want to plot a graph of an equation in Python which has a solution variable at both sides in form of some function. The equation is:
i = Ip - Io*(exp((V+i*R1)/(n*Vt)) - 1) - (V +I*R1)/(R2)
where Ip, Io, n, R1, R2, Vt
are some constants.
I want to iterate V
in the range (0,10)
and want to get values for i
using Python and plot a V-i
graph.
import numpy as np
from sympy import *
import matplotlib.pyplot as plt
r = 50
V = np.linspace(0,10,r)
def current():
current = []
for t in V:
i = np.zeros(r)
Ipv = 3
Rs = 0.221
Rsh = 415
n = 2
m = 1.5
T = 302
Eg = 1.14
K = 1.3
Vt = T/11600
Io = K*(T**m)*exp(-Eg/(n*Vt))
i = Ipv - Io *(exp((t + Rs*i)/(n*Vt)) - 1) - (t + Rs * i)/Rsh
current.append(i)
return np.array(current)
Icurrent = current()
plt.plot(V,Icurrent)
plt.show()
I did this but this not working.
Any suggestions welcome.
Upvotes: 0
Views: 213
Reputation: 12410
It seems, your problem is that you mix numpy
arrays with a scalar math
function. Don't do this. Substitute it with the appropriate numpy
function:
import numpy as np
import matplotlib.pyplot as plt
r = 50
V = np.linspace(0,10,r)
print(V)
def current():
current = []
for t in V:
i = np.zeros(r)
Ipv = 3
Rs = 0.221
Rsh = 415
n = 2
m = 1.5
T = 302
Eg = 1.14
K = 1.3
Vt = T/11600
Io = K*(T**m)*np.exp(-Eg/(n*Vt))
i = Ipv - Io *(np.exp((t + Rs*i)/(n*Vt)) - 1) - (t + Rs * i)/Rsh
current.append(i)
return np.array(current)
Icurrent = current()
plt.plot(V,Icurrent)
plt.show()
I would have suggested using scipy.fsolve
, but seemingly your approach is working.
Upvotes: 1