将公式与数组中的 x 值相结合

Integrating formula with x values from array

我想为数组中的所有 x 值集成一个公式。 如何将数组用于 x 的值?

我需要先手动积分公式吗? 需要积分的原始公式为 (a*(4-x))-b

同样重要的是要注意,数组确实包含多个相同的值

假设您正在尝试在 [0, 4] 范围内求整数,您可以执行以下操作而不需要手动求积分:

import scipy.integrate as integrate
import scipy.special as special

# Defining the function you're integrating by
def this_funct(x, a, b):
    return (a*(4-x)) - b

# Range you are integrating along
bottom_of_range = 0
top_of_range = 4

# Change a and b to be whatever you want
a = 3
b = 4

# Result contains the integral of this_funct in the range (bottom_of_range, top_of_range).
result = integrate.quad(lambda x: this_funct(x, a, b), bottom_of_range, top_of_range)[0]

您可以根据需要更改 bottom_of_rangetop_of_rangeab