Created
October 5, 2020 11:08
-
-
Save kayhman/64e803e4570b0201ae3c12998193e3db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from forward_autodiff import DualFloat | |
def simple_polynome(a, b): | |
return lambda x : x**2 * a + b | |
def squared_polynome(a, b, c): | |
return lambda x : x**2 * a + x * b + c | |
def squared_polynome_check(a, b, c): | |
return lambda x : 2*x * a + b | |
f1 = simple_polynome(3.0, 0.0) | |
f2 = squared_polynome(3.0, 2.0, 1.0) | |
f3 = squared_polynome_check(3.0, 2.0, 1.0) | |
r = f1(DualFloat(4, 1.0)) | |
print(r) | |
# > DF(48.0, 24.0) | |
r = f2(DualFloat(3, 1.0)) | |
check = f3(3) | |
print(r) | |
# > DF(34.0, 20.0) | |
print(check) | |
# > 20.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment