Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
minimathematica
Commits
5f83d117
Commit
5f83d117
authored
6 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
Add B/A tests
parent
5b518fb4
master
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/2.B/test_taylor.py
+22
-0
tests/2.B/test_taylor.py
tests/3.A/test_estimation.py
+31
-0
tests/3.A/test_estimation.py
with
53 additions
and
0 deletions
+53
-0
tests/2.B/test_taylor.py
0 → 100644
View file @
5f83d117
from
sympy
import
series
,
atan
,
nsimplify
from
src.taylor
import
estimate
import
pytest
from
sympy.abc
import
x
def
ref_taylor
(
f
,
a
,
N
,
xval
):
return
nsimplify
(
series
(
f
,
x
=
x
,
x0
=
a
,
n
=
N
).
removeO
().
subs
(
x
,
xval
).
doit
())
at_one_tenth
=
[(
0
,
N
,
0.1
)
for
N
in
range
(
15
)]
at_two_tenths
=
[(
0
,
N
,
0.2
)
for
N
in
range
(
15
)]
at_one
=
[(
0
,
N
,
1
)
for
N
in
range
(
15
)]
@
pytest
.
mark
.
parametrize
(
'a, N, xval'
,
at_one_tenth
+
at_two_tenths
+
at_one
)
def
test_arctan_taylor
(
a
,
N
,
xval
):
result
=
estimate
(
'arctan'
,
xval
,
a
,
atan
(
a
),
N
)
ref
=
ref_taylor
(
atan
(
x
),
a
,
N
,
xval
)
print
(
float
(
result
),
float
(
ref
))
assert
abs
(
float
(
result
)
-
float
(
ref
))
<
10
**
(
-
8
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/3.A/t
aylor_tests_not_ready
.py
→
tests/3.A/t
est_estimation
.py
View file @
5f83d117
from
sympy
import
series
,
atan
,
oo
,
nsimplify
,
poly
,
diff
from
decimal
import
Decimal
from
sympy
import
series
,
atan
,
nsimplify
,
diff
from
sympy.calculus.util
import
Interval
,
maximum
from
sympy.abc
import
x
import
math
from
src.taylor
import
arctan
from
decimal
import
Decimal
import
pytest
from
sympy.abc
import
x
def
term
(
N
,
xval
,
a
):
ivl
=
Interval
(
xval
-
0.001
,
a
+
0.001
)
+
Interval
(
a
-
0.001
,
xval
+
0.001
)
d
=
diff
(
f
,
x
,
N
+
1
)
d
=
diff
(
atan
(
x
)
,
x
,
N
+
1
)
M
=
maximum
(
d
,
x
,
ivl
)
return
nsimplify
(
abs
(((
M
*
((
x
-
a
)
**
(
N
+
1
))
/
math
.
factorial
(
N
+
1
)).
subs
(
x
,
xval
))))
f
=
atan
(
x
)
def
ref_taylor
(
f
,
a
,
N
,
xval
):
return
nsimplify
(
series
(
f
,
x
=
x
,
x0
=
a
,
n
=
N
).
removeO
().
subs
(
x
,
xval
).
doit
())
def
approx_atan
(
N
,
xval
,
a
):
return
nsimplify
(
series
(
f
,
x
=
x
,
x0
=
a
,
n
=
N
+
1
).
removeO
().
subs
(
x
,
xval
).
doit
()
),
term
(
N
,
xval
,
a
)
return
ref_taylor
(
atan
(
x
),
a
,
N
,
xval
),
term
(
N
,
xval
,
a
)
xval
=
0.2
for
q
in
range
(
0
,
20
):
@
pytest
.
mark
.
parametrize
(
'q'
,
range
(
20
))
def
test_arctan
(
q
):
xval
=
q
/
10
result
,
error
=
approx_atan
(
11
,
xval
,
0
)
#print(xval, float(error), abs(math.atan(xval) - result) <= float(error))
_
,
error
=
approx_atan
(
10
,
xval
,
0
)
v
,
e
=
arctan
(
Decimal
(
xval
))
#print(xval, float(error), abs(math.atan(xval) - float(v)) <= float(error))
print
(
xval
,
float
(
e
),
abs
(
math
.
atan
(
xval
)
-
float
(
v
)),
abs
(
math
.
atan
(
xval
)
-
float
(
v
))
<=
float
(
e
))
if
xval
<
0.9
:
assert
0
<=
float
(
e
)
-
float
(
error
)
<
0.003
assert
abs
(
math
.
atan
(
xval
)
-
float
(
v
))
<=
float
(
e
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help