pi and e not evaluated when i use my own classes
This question might be related to this question: http://ask.sagemath.org/question/966/...
I have a symbolic calculation and I do evaluate it numerically. Within one of my classes (within my notebook; no external files) I evaluate this term
-1/e^(1/10*abs(-0.0555555555556*pi - 26714619/51021164)) + 1
within a for loop.
I am getting the following error:
File "", line 1, in <module> File "/tmp/tmpkItECC/___code___.py", line 113, in <module> __temp=MuObject.calcValue((mu_enlacement[i])(**param_dict)) File "/tmp/tmpJuxeqk/___code___.py", line 97, in calcValue self._result[self._k,_sage_const_0 ]=R(self._value(theta_1=item[_sage_const_0 ],mu_t=item[_sage_const_1 ],mu_j=item[_sage_const_1 ])) File "parent.pyx", line 988, in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:7326) File "coerce_maps.pyx", line 156, in sage.structure.coerce_maps.NamedConvertMap._call_ (sage/structure/coerce_maps.c:4235)
File "expression.pyx", line 862, in sage.symbolic.expression.Expression._mpfr_ (sage/symbolic/expression.cpp:5117)
File "expression.pyx", line 796, in sage.symbolic.expression.Expression._eval_self (sage/symbolic/expression.cpp:4912) TypeError: Cannot evaluate symbolic expression to a numeric value.
If I copy paste the expression
print
(-1/e^(1/10*abs(-0.0555555555556*pi - 26714619/51021164)) + 1).n()
to my notebook it evaluates fine to:
0.0674319647572598
I even tried to replace pi and e using a dictionary but I can't get it working.
Any ideas what i am doing wrong?
Thanks in advance,
Markus P.S.: I can make the notebook public if usefull
The problem seems to be related to what is imported. Another version where the object calculating the values are created earlier works fine. I imported matplotlib as plt and numpy as np so no modules of these should be conflicting, right?
I'm not sure what's happening. If you make the notebook public, or simply make a small self-contained example (always useful!) showing the problem, we can have a look.
def expr(): return -1/exp(1/10*abs(-0.0555555555556*n(pi) - 26714619/51021164)) + 1 (I'm often using workarounds of this type. Does it work for you?)
@achrzesz: if this is an answer, make it an answer and get karma (as well as make it easier to search for)!
@kcrisman As DSM stated without a self-contained code snippet it is difficult to give a definite answer. My guess is that to obtain a numerical result, the symbolic arguments pi,e should be replaced by n(pi),n(e) or RR(pi),RR(e)
The big question that remains to me is how to do that after miles of symbolic calculations. I tried using a dictionary and that failes. Copy paste is not a too good solution also since the argument I posted is (by far) the shortest. In that case I'd prefer to copy paste it completely to python, because my calculations are to slow and memory consuming anyway. Second I do not get what the difference of RR(-1/exp(1/10*abs(-0.0555555555556*(pi) - 26714619/51021164)) + 1) and -1/RR(e)^(1/10*abs(-0.0555555555556*RR(pi) - 26714619/51021164)) + 1 should be.
The Worksheet now is public at http://www.sagenb.org/home/pub/3912. The calculations failing are in the cell containing ###### 7 ######## and the following cell. Sorry for the dirty hacks in there and thanks in advance ;-)