本文整理匯總了Python中function.Function.power方法的典型用法代碼示例。如果您正苦於以下問題:Python Function.power方法的具體用法?Python Function.power怎麽用?Python Function.power使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類function.Function
的用法示例。
在下文中一共展示了Function.power方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_split
# 需要導入模塊: from function import Function [as 別名]
# 或者: from function.Function import power [as 別名]
def test_split(self):
# If this ever breaks, we should solve the problem by writing a
# new kind of Function that turns a lambda expression into a
# Function. That way, it will never be simplified.
# f = x^2 + x
f = Function.sum(Function.power(Function.identity(),
Function.constant(2)),
Function.identity())
# f(-1) = 0, f(0) = 0, f(-.5) = -.25
# The range of f on [-1,0] is [-.25,0]
# f([-1,0]) = [-1,1]
# f([-1,-.5]) = [-.75,.5]
# f([-.5,0]) = [-.5,.25]
# This will never finish, since it asks for the exact bounds
self.assertTrue(is_bounded(f, Interval(-1,0), Interval(-1/4,0))
is None)
# g = 1/2*x^3-3/2*x
g = Function.sum(Function.product(
Function.constant(.5),
Function.power(Function.identity(),
Function.constant(3))),
Function.product(Function.constant(-1.5),
Function.identity()))
self.assertEqual(is_bounded(g, Interval(-1.5,1.5), Interval(-.9,1)),
False)
# This encounters a ValueError on the first split so should
# return None
h = Function.quotient(Function.constant(1), Function.identity())
self.assertTrue(is_bounded(h, Interval(-1,1), Interval(-5,5)) is None)
示例2: test_cubic_derivative
# 需要導入模塊: from function import Function [as 別名]
# 或者: from function.Function import power [as 別名]
def test_cubic_derivative(self):
a = cubic_derivative_approximation(
Function.power(Function.identity(), Function.constant(3)),
4, 10)
self.assertAlmostEqual(a(0), 0)
self.assertAlmostEqual(a(2), 8)
self.assertAlmostEqual(a(5), 125)
self.assertAlmostEqual(a(12), 1728)
self.assertAlmostEqual(a(-3), -27)
示例3: test_approx
# 需要導入模塊: from function import Function [as 別名]
# 或者: from function.Function import power [as 別名]
def test_approx(self):
f = Function.identity()
for a in approximate(f, 0, 1):
self.assertTrue(isinstance(a, Function))
self.assertTrue(isinstance(a, CubicSpline))
# We may someday generate approximations that don't go through
# the endpoints, and remove these tests. Until then, they
# help verify that the approximation formulas are correct.
self.assertEqual(a(0.0), 0.0)
self.assertEqual(a(1.0), 1.0)
# (-x^2 - 1) ^ .5
bad = Function.power(Function.sum(Function.product(
Function.constant(-1),
Function.power(Function.identity(), Function.constant(2))),
Function.constant(-1)),
Function.constant(.5))
self.assertEqual(list(approximate(bad, 0, 1)), [])
示例4: test_depth
# 需要導入模塊: from function import Function [as 別名]
# 或者: from function.Function import power [as 別名]
def test_depth(self):
f = Function.sum(Function.power(Function.identity(),
Function.constant(2)),
Function.identity())
# This requires splitting in half
self.assertTrue(is_bounded(f, Interval(-1,0), Interval(-3/4,1/2), 1))
self.assertEqual(is_bounded(f, Interval(-1,0), Interval(-3/4,1/2), 0),
None)
# This requires 3 levels of recursion
self.assertTrue(is_bounded(f, Interval(-1,0), Interval(-3/8,1/8), 3))
self.assertEqual(is_bounded(f, Interval(-1,0), Interval(-3/8,1/8), 2),
None)
# This requires 8 levels of recursion
self.assertTrue(is_bounded(f, Interval(-1,0), Interval(-65/256,1/256),
8))
self.assertEqual(is_bounded(f, Interval(-1,0), Interval(-65/256,1/256),
7), None)