0

I have this sympy expression.

I am not sure why evalf function doesn't properly evaluate this expression and still I don't get an actual numerical value out of it?

    value = {t1: _t1, t2: _t2, t3: _t3, x_mid: _x_mid, theta: _theta, focal_length: _focal_length, vec_20: vec_2[0],
         vec_21: vec_2[1], vec_22: vec_2[2], r: radius}

    ansx = root1[i][0].evalf(subs=value)

After the following piece of code is run:

        ansx = root1[i][0].evalf(subs=value)

I get the following for ansx:

enter image description here

where root[i][0] is:

enter image description here

I had created a minimal expression that shows evalf should work for sympy:

In [7]: omega, t = sympy.symbols("omega, t")

In [8]: s = sympy.pi * sympy.cos(omega*t)

In [9]: s
Out[9]: pi*cos(omega*t)

In [10]: print(s.evalf().subs({t: 0}))
3.14159265358979
Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
  • 2
    Try to come up with something smaller that has the same problem, such as a couple of the terms. Something that we can copy-n-paste and run ourselves. – hpaulj Dec 31 '20 at 00:04
  • Interesting question, I think maybe it would help to to show what are the values `_t1`, `_t2`, etc., and also to show what is the value of `roots[i][0]` in a plain text form (not an image), so that others can copy the code and run it for themselves. – Robert Dodier Jan 01 '21 at 19:26

0 Answers0