* adding scipy integrate, initial check-in * compile unix double-precision, select integrations algos * bumping ulab version number to 6.7.0 * adding documentation * documentation fix * documentation fix * documentation fix * rewritten in some places * complex number error handling * added test cases * resolved importing scipy.integrate * resolved importing scipy.integrate #2 * build integrate only when we have MICROPY_FLOAT_IMPL_DOUBLE * reverting commita4c0c0b* re-pushing failed commit * Revert "re-pushing failed commit" This reverts commita10e89fe14. * improve tests using math.isclose() * enabled fp32 builds * removed conditional includes * adapted to new function names, corrected importing * function names similar to in CPython scipy.integrate, some minor corrections * major rewrite representing the name changes, mapping to CPython scipy.integrate, more background info
28 lines
610 B
Python
28 lines
610 B
Python
import sys
|
|
from math import *
|
|
|
|
try:
|
|
from ulab import scipy
|
|
except ImportError:
|
|
import scipy
|
|
|
|
f = lambda x: x * sin(x) * exp(x)
|
|
a=1
|
|
b=2
|
|
|
|
(res, err) = scipy.integrate.tanhsinh(f, a, b)
|
|
if isclose (res, 7.11263821415851) and isclose (err, 5.438231077315757e-14):
|
|
print (res, err)
|
|
|
|
res = scipy.integrate.romberg(f, a, b)
|
|
if isclose (res, 7.112638214158507):
|
|
print (res)
|
|
|
|
res = scipy.integrate.simpson(f, a, b)
|
|
if isclose (res, 7.112638214158494):
|
|
print (res)
|
|
|
|
(res, err) = scipy.integrate.quad(f, a, b)
|
|
if isclose (res, 7.112638214158507) and isclose (err, 7.686723611780195e-14):
|
|
print (res, err)
|
|
|