Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90393002
heaviside_fitting.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 1, 06:42
Size
2 KB
Mime Type
text/x-python
Expires
Sun, Nov 3, 06:42 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22067577
Attached To
R6746 RationalROMPy
heaviside_fitting.py
View Options
# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import
numpy
as
np
from
rrompy.utilities.poly_fitting.heaviside
import
(
polybases
,
polyfitname
,
polydomcoeff
,
heaviside2rational
,
rational2heaviside
)
from
rrompy.utilities.poly_fitting.polynomial.polynomial_interpolator
import
(
PolynomialInterpolator
,
PolynomialInterpolatorNodal
)
def
test_monomial_heaviside
():
polyhsname
=
"MONOMIAL_HEAVISIDE"
assert
polyhsname
in
polybases
fitname
=
polyfitname
(
polyhsname
)
domcoeff
=
polydomcoeff
(
5
,
polyhsname
)
assert
fitname
==
"polyfit_heaviside"
assert
np
.
isclose
(
domcoeff
,
1.
,
rtol
=
1e-5
)
pls
=
np
.
array
([
-
5.
,
0.
,
2.
])
cHS
=
np
.
array
([
4.
,
1.
,
-
10.
,
-
25.
,
4.
,
.
25
])
cNum
=
np
.
array
([
-
10.
,
195.
,
-
120.
,
-
15.5
,
4.75
,
.
25
])
cDen
=
np
.
array
([
0.
,
-
10.
,
3.
,
1.
])
cNum
/=
np
.
linalg
.
norm
(
cDen
)
cDen
/=
np
.
linalg
.
norm
(
cDen
)
numI
=
PolynomialInterpolator
()
numI
.
coeffs
,
numI
.
npar
,
numI
.
polybasis
=
cNum
,
1
,
"MONOMIAL"
denI
=
PolynomialInterpolator
()
denI
.
coeffs
,
denI
.
npar
,
denI
.
polybasis
=
cDen
,
1
,
"MONOMIAL"
numA
,
denA
=
heaviside2rational
(
cHS
,
pls
,
[
-
10.
,
10.
])
assert
isinstance
(
denA
,
PolynomialInterpolatorNodal
)
cA
,
plsA
,
_
=
rational2heaviside
(
numI
,
denI
,
[
-
10.
,
10.
])
numA
.
coeffs
/=
(
denA
.
coeffs
[
1
]
/
cDen
[
1
])
denA
.
coeffs
/=
(
denA
.
coeffs
[
1
]
/
cDen
[
1
])
assert
np
.
allclose
(
numA
.
coeffs
,
numI
.
coeffs
,
atol
=
1e-5
)
assert
np
.
allclose
(
denA
.
coeffs
,
denI
.
coeffs
,
atol
=
1e-5
)
assert
np
.
allclose
(
cA
,
cHS
,
atol
=
1e-5
)
assert
np
.
allclose
(
plsA
,
pls
,
atol
=
1e-5
)
def
test_chebyshev_heaviside
():
polyhsname
=
"CHEBYSHEV_HEAVISIDE"
assert
polyhsname
in
polybases
fitname
=
polyfitname
(
polyhsname
)
domcoeff
=
polydomcoeff
(
5
,
polyhsname
)
assert
fitname
==
"chebfit_heaviside"
assert
np
.
isclose
(
domcoeff
,
16
,
rtol
=
1e-5
)
pls
=
np
.
array
([
-
5.
,
0.
,
2.
+
1.j
,
7
])
cHS
=
np
.
array
([
4.
,
1.
,
25.
,
-
10.
,
-
25.
,
4.
,
.
25
],
dtype
=
np
.
complex
)
numA
,
denA
=
heaviside2rational
(
cHS
,
pls
,
[
-
10.
,
10.
])
cA
,
plsA
,
_
=
rational2heaviside
(
numA
,
denA
,
[
-
10.
,
10.
])
assert
np
.
allclose
(
cA
,
cHS
,
atol
=
1e-5
)
assert
np
.
allclose
(
plsA
,
pls
,
atol
=
1e-5
)
Event Timeline
Log In to Comment