简体   繁体   中英

Using Simpson's Rule in Python

I'm trying to get an array from an f(x) function this way:

array=list()

for i in range(x):
    parameter= z+(i*change)
    array=f(parameter)

Note that x is an integer, z and change are floats established in my code.

The next thing I want is to use simpson's rule using the simps function in scipy. I tried this:

Simpsons= integrate.simps(array, dx=change)

It says there is an error How can I solve this?

The problem line is array=f(param) . You're assigning array to the result of f , not appending it. You should do array.append(f(param)) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM