|
1 | | -import sys |
2 | | -from math import * |
3 | | - |
4 | 1 | try: |
5 | | - from ulab import scipy |
| 2 | + from ulab import scipy as spy |
| 3 | + from ulab import numpy as np |
6 | 4 | except ImportError: |
7 | 5 | import scipy |
8 | 6 |
|
9 | | -f = lambda x: x * sin(x) * exp(x) |
10 | | -a=1 |
11 | | -b=2 |
| 7 | +import math |
| 8 | + |
| 9 | +f = lambda x: x * np.sin(x) * np.exp(x) |
| 10 | +a = 1 |
| 11 | +b = 2 |
12 | 12 |
|
13 | | -(res, err) = scipy.integrate.tanhsinh(f, a, b) |
14 | | -if isclose (res, 7.11263821415851) and isclose (err, 5.438231077315757e-14): |
15 | | - print (res, err) |
16 | | - |
17 | | -res = scipy.integrate.romberg(f, a, b) |
18 | | -if isclose (res, 7.112638214158507): |
19 | | - print (res) |
| 13 | +(res, err) = spy.integrate.tanhsinh(f, a, b) |
| 14 | +print('testing tanhsinh') |
| 15 | +print(math.isclose(res, 7.11263821415851, rel_tol=1E-6, abs_tol=1E-6)) |
| 16 | +print() |
20 | 17 |
|
21 | | -res = scipy.integrate.simpson(f, a, b) |
22 | | -if isclose (res, 7.112638214158494): |
23 | | - print (res) |
| 18 | +print('testing romberg') |
| 19 | +res = spy.integrate.romberg(f, a, b) |
| 20 | +print(math.isclose(res, 7.112638214158507, rel_tol=1E-6, abs_tol=1E-6)) |
| 21 | +print() |
24 | 22 |
|
25 | | -(res, err) = scipy.integrate.quad(f, a, b) |
26 | | -if isclose (res, 7.112638214158507) and isclose (err, 7.686723611780195e-14): |
27 | | - print (res, err) |
| 23 | +print('testing simpson') |
| 24 | +res = spy.integrate.simpson(f, a, b) |
| 25 | +print(math.isclose(res, 7.112638214158507, rel_tol=1E-6, abs_tol=1E-6)) |
| 26 | +print() |
28 | 27 |
|
| 28 | +print('testing quad') |
| 29 | +(res, err) = spy.integrate.quad(f, a, b) |
| 30 | +print(math.isclose(res, 7.112638214158507, rel_tol=1E-6, abs_tol=1E-6)) |
0 commit comments