如何通过以下代码绘制功率曲线?

时间:2018-05-22 09:24:39

标签: python numpy matplotlib python-3.6

在代码中,我试图绘制图Power(p)vs voltage(Vpv)但我的代码没有给出结果。

import numpy as np
import math
from numpy import *
import matplotlib.pyplot as plt
plt.style.use('ggplot')

r = 50
Vpv = np.linspace(0,0.6,r) # Vpv = panel voltage

Rs = 0  # series resistance
Rsh = math.inf  # parallel resistance
n = 2       # ideality constant depends on semiconductor material
m = 1.5     # another constant depends on dopping
T = 298    # temperature in kelvin
Eg = 1.14   # band gap energy in ev
K = 0.13      # constant
Vt = T/11600  #thermal voltage
Io = K*(T**m)*exp(-Eg/(n*Vt))   # Io = diode current
print(Io)
Isc = Io*(10**9)

def current():
    current = []  #initializing current array as null
    for t in Vpv:
        Ipv = np.zeros(r)  #initializing panel current(Ipv) as zero  

        Ipv = Isc - Io *(exp((t + Rs*Ipv)/(n*Vt)) - 1) - (t + Rs*Ipv)/Rsh
        current.append(Ipv)
    return np.array(current)

Icurrent = current()
#power = Vpv * Icurrent
power = np.multiply(Vpv, Icurrent)
plt.plot(Vpv,power,'b')
#plt.plot(Vpv,Icurrent,'r')
plt.xlabel('Panel VOltage(V)')
plt.ylabel('Panel Current(A) and Power(W)')
plt.show()

还尝试使用像no.multiply(arr1,arr2)这样的数组乘法,但这也无效。

我使用数组乘法获得以下图表 - Output of the above code

但它应该有以下形状 - Expected shape of output

任何建议欢迎。

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题。我得到了正确的图表。

import numpy as np
import math
from numpy import *
import matplotlib.pyplot as plt
plt.style.use('ggplot')

r = 50
Vpv = np.linspace(0,1.1,r) # Vpv = panel voltage

Rs = 0  # series resistance
Rsh = math.inf  # parallel resistance
n = 2       # ideality constant depends on semiconductor material
m = 1.5     # another constant depends on dopping
T = 298    # temperature in kelvin
Eg = 1.14   # band gap energy in ev
K = 0.13      # constant
Vt = T/11600  #thermal voltage
Io = K*(T**m)*exp(-Eg/(n*Vt))   # Io = diode current
print(Io)
Isc = Io*(10**9)

def current():
    current = []  #initializing current array as null
    for t in Vpv:
        Ipv = 0  #initializing panel current(Ipv) as zero  

        Ipv = Isc - Io *(exp((t + Rs*Ipv)/(n*Vt)) - 1) - (t + Rs*Ipv)/Rsh
        current.append(Ipv)
    return np.array(current)

Icurrent = current()
p = Vpv * Icurrent
plt.plot(Vpv,p,'b')
plt.plot(Vpv,Icurrent,'r')
plt.xlabel('Panel VOltage(V)')
plt.ylabel('Panel Current(A)')
plt.ylim(0,max(Icurrent)+ 10)
plt.plot((-0.1, max(Vpv)), (0,0), 'k')
plt.plot((0,0),(-3,8), 'k')
plt.show()