首页 > 解决方案 > How to plot a power curve by following code?

问题描述

In the code, I tried to plot a graph Power(p) vs voltage (Vpv) but my code is not giving the result.

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()

Is also tried to use array multiplication like no.multiply(arr1,arr2) but this is also not working.

I am getting the following graph using array multiplication - Output of the above code

but it should come in the following shape - Expected shape of output

Any suggestion Welcome.

标签: pythonnumpymatplotlibpython-3.6

解决方案


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

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()

推荐阅读