diff --git a/lms/lib/symmath/formula.py b/lms/lib/symmath/formula.py index c71a79bac7..1698b004d9 100644 --- a/lms/lib/symmath/formula.py +++ b/lms/lib/symmath/formula.py @@ -409,8 +409,7 @@ class formula(object): if 'hat' in usym: sym = my_sympify(usym) else: - if usym == 'i': print "options=", self.options - if usym == 'i' and 'imaginary' in self.options: # i = sqrt(-1) + if usym == 'i' and self.options is not None and 'imaginary' in self.options: # i = sqrt(-1) sym = sympy.I else: sym = sympy.Symbol(str(usym)) diff --git a/lms/lib/symmath/symmath_check.py b/lms/lib/symmath/symmath_check.py index 09810b8820..bcb4a0d490 100644 --- a/lms/lib/symmath/symmath_check.py +++ b/lms/lib/symmath/symmath_check.py @@ -175,6 +175,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None do_matrix = 'matrix' in (options or '') do_qubit = 'qubit' in (options or '') do_imaginary = 'imaginary' in (options or '') + do_numerical = 'numerical' in (options or '') # parse expected answer try: @@ -196,6 +197,13 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None msg += '

You entered: %s

' % to_latex(fans) return {'ok': False, 'msg': msg} + if do_numerical: # numerical answer expected - force numerical comparison + if abs(abs(fans - fexpect) / fexpect) < threshold: + return {'ok': True, 'msg': msg} + else: + msg += '

You entered: %s (note that a numerical answer is expected)

' % to_latex(fans) + return {'ok': False, 'msg': msg} + if fexpect == fans: msg += '

You entered: %s

' % to_latex(fans) return {'ok': True, 'msg': msg}