STEMQs
STEMQs

Reputation: 95

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?

Upvotes: 0

Views: 206

Answers (1)

Christopher Paterson
Christopher Paterson

Reputation: 186

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

Upvotes: 1

Related Questions