【发布时间】:2021-09-21 16:33:12
【问题描述】:
我正在尝试获取 4 个不同变量的值,同时给出以下等式:
f(t)=k1t+k2(t^2)+k3*(c^(t*0.15))
我还得到了以下结果: f(10)=25; f(15)=130; f(20)=650
我正在尝试在 python 中使用 sympy 的 solve() 来获取未知变量(k 和 c)的这些值,并且当 t=10 时我正在使用等式
from sympy import symbols, Eq, solve
import math
import sys
def Find(t):
k1 = symbols(' k1')
k2 = symbols(' k2')
k3 = symbols(' k3')
c = symbols(' c')
eq1 = Eq((k1*t)+(k2*(t**2))+(k3*(c**(0.15*t)))==25)
sol = solve((eq1), (k1, k2, k3, c))
num = {sol[k1]}
print(num)
while(1):
print("\nValues of variables")
t = 10
Find(t)
print("\nEnd")
sys.exit()
我的问题在于尝试在 {sol[k1]} 中引用它时无法获得 k1 的值。如果我将 k1 作为索引,我会收到此消息
TypeError: list indices must be integers or slices, not Symbol
如果我尝试用 0 或任何数字替换它,我会收到以下消息:
IndexError: list index out of range
【问题讨论】: