为什么我得到一个空列表作为答案?

时间:2022-05-08 22:50:18

I am supposed to be printing out all values for r (which should be a list of 5 values) but for some reason I am getting an empty list [ ] as the answer. All of the inputs to the function are single values except for the lst variable, which is a list of 5 values. Any idea on why I am getting an empty list? All of the code I am using can be seen below.

我应该打印出r的所有值(应该是5个值的列表)但由于某种原因我得到一个空列表[]作为答案。除了lst变量之外,函数的所有输入都是单个值,lst变量是5个值的列表。我知道为什么我得到一个空列表的任何想法?我正在使用的所有代码都可以在下面看到。

from math import pi
from sympy import solve


class SolarHeating:        
    def waterheated(self, T0, T, lst, Cp, Eg, r):
        self.m = var('m')
        self.T0 = T0
        self.T = T
        self.lst = lst
        self.Cp = Cp
        self.Eg = Eg
        self.r = r

        A = pi * self.r**2
        Qt = self.Eg * A
        F = [(self.T - self.T0) * self.m * self.Cp / Qt - x for x in self.lst]
        self.m = solve(F, self.m)

        return self.m


lst = [0, .25, .5, .75, 1.0]
a = SolarHeating()   
m = a.waterheated(20, 40, lst, 4.2, .928, .128) 
print(m)

1 个解决方案

#1


2  

    ...
    F = [(self.T-self.T0)*self.m*self.Cp/Qt-x for x in self.lst]
    self.m = solve(F,self.m)
    return self.m

This is most probably a math problem, not a code problem. Print the value of F and check that it really has a solution that solve() should return.

这很可能是数学问题,而不是代码问题。打印F的值并检查它是否确实有一个solve()应该返回的解决方案。

#1


2  

    ...
    F = [(self.T-self.T0)*self.m*self.Cp/Qt-x for x in self.lst]
    self.m = solve(F,self.m)
    return self.m

This is most probably a math problem, not a code problem. Print the value of F and check that it really has a solution that solve() should return.

这很可能是数学问题,而不是代码问题。打印F的值并检查它是否确实有一个solve()应该返回的解决方案。