如何求解方程两边都有函数形式的解变量的方程

How to solve an equation which has a solution variable in form of function at both side of equation

我想绘制 Python 方程的图形,方程的两边都有一个函数形式的解变量。 等式是:

i = Ip - Io*(exp((V+i*R1)/(n*Vt)) - 1) - (V +I*R1)/(R2)

其中 Ip, Io, n, R1, R2, Vt 是一些常量。

我想在 (0,10) 范围内迭代 V 并希望使用 Python 获取 i 的值并绘制 V-i 图表。

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

我这样做了,但是没用。

欢迎提出任何建议。

看来,您的问题是将 numpy 数组与标量 math 函数混合使用。 将其替换为适当的 numpy 函数:

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

输出:

我本来建议使用 scipy.fsolve,但看来你的方法奏效了。