def test_trig(self): m = ConcreteModel() m.x = Var(bounds=(pi / 4, pi / 2), initialize=pi / 4) mc_expr = mc(tan(atan((m.x)))) self.assertAlmostEqual(mc_expr.lower(), pi / 4) self.assertAlmostEqual(mc_expr.upper(), pi / 2) m.y = Var(bounds=(0, sin(pi / 4)), initialize=0) mc_expr = mc(asin((m.y))) self.assertEqual(mc_expr.lower(), 0) self.assertAlmostEqual(mc_expr.upper(), pi / 4) m.z = Var(bounds=(0, cos(pi / 4)), initialize=0) mc_expr = mc(acos((m.z))) self.assertAlmostEqual(mc_expr.lower(), pi / 4) self.assertAlmostEqual(mc_expr.upper(), pi / 2)
def test_trig(self): m = ConcreteModel() m.x = Var(bounds=(pi / 4, pi / 2), initialize=pi / 4) mc_expr = mc(tan(atan((m.x)))) self.assertAlmostEqual(mc_expr.lower(), pi / 4) self.assertAlmostEqual(mc_expr.upper(), pi / 2) m.y = Var(bounds=(0, sin(pi / 4)), initialize=0) mc_expr = mc(asin((m.y))) self.assertEqual(mc_expr.lower(), 0) self.assertAlmostEqual(mc_expr.upper(), pi / 4) m.z = Var(bounds=(0, cos(pi / 4)), initialize=0) mc_expr = mc(acos((m.z))) self.assertAlmostEqual(mc_expr.lower(), pi / 4) self.assertAlmostEqual(mc_expr.upper(), pi / 2)
def _sum(*x): return sum(i for i in x) def _nondifferentiable(*x): raise NondifferentiableError( "The sub-expression '%s' is not differentiable with respect to %s" % (x[0], x[1])) _operatorMap = { sympy.Add: _sum, sympy.Mul: _prod, sympy.Pow: lambda x, y: x**y, sympy.exp: lambda x: core.exp(x), sympy.log: lambda x: core.log(x), sympy.sin: lambda x: core.sin(x), sympy.asin: lambda x: core.asin(x), sympy.sinh: lambda x: core.sinh(x), sympy.asinh: lambda x: core.asinh(x), sympy.cos: lambda x: core.cos(x), sympy.acos: lambda x: core.acos(x), sympy.cosh: lambda x: core.cosh(x), sympy.acosh: lambda x: core.acosh(x), sympy.tan: lambda x: core.tan(x), sympy.atan: lambda x: core.atan(x), sympy.tanh: lambda x: core.tanh(x), sympy.atanh: lambda x: core.atanh(x), sympy.ceiling: lambda x: core.ceil(x), sympy.floor: lambda x: core.floor(x), sympy.Derivative: _nondifferentiable, } except ImportError: #pragma:nocover
def _sum(*x): return sum(i for i in x) def _nondifferentiable(*x): raise NondifferentiableError( "The sub-expression '%s' is not differentiable with respect to %s" % (x[0],x[1]) ) _operatorMap = { sympy.Add: _sum, sympy.Mul: _prod, sympy.Pow: lambda x,y: x**y, sympy.log: lambda x: core.log(x), sympy.sin: lambda x: core.sin(x), sympy.asin: lambda x: core.asin(x), sympy.sinh: lambda x: core.sinh(x), sympy.asinh: lambda x: core.asinh(x), sympy.cos: lambda x: core.cos(x), sympy.acos: lambda x: core.acos(x), sympy.cosh: lambda x: core.cosh(x), sympy.acosh: lambda x: core.acosh(x), sympy.tan: lambda x: core.tan(x), sympy.atan: lambda x: core.atan(x), sympy.tanh: lambda x: core.tanh(x), sympy.atanh: lambda x: core.atanh(x), sympy.ceiling: lambda x: core.ceil(x), sympy.floor: lambda x: core.floor(x), sympy.Derivative: _nondifferentiable, } except ImportError: #pragma:nocover