evalf in sympy returns expression instead of value in single variable expression

Michael Eliosov

I'm trying to use sympy to compute Taylor series, but something seems to be wrong.

I have an expression that looks like this (the first two terms of e^sin(x)):

e**sin(x)*x*log(e)*cos(x) + 1.0

but when I run evalf on it it returns the expression itself:

x=symbols('x')
print(sympify('e**sin(x)*x*log(e)*cos(x) + 1.0').evalf(subs={x:1})) 
# returns e**sin(x)*x*log(e)*cos(x) + 1.0

This happens regardless of what value for x I pick

Oscar Benjamin

Use E for the Euler number:

In [18]: x=symbols('x')
    ...: print(sympify('E**sin(x)*x*log(E)*cos(x) + 1.0').evalf(subs={x:1}))
2.25338076749345

Alternatively use e.g. exp(sin(x)) rather than E**sin(x).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

evalf and subs in sympy on single variable expression returns expression instead of expected float value

Sympy evalf doesn't work with 1 variable subs() in 2 variable expression

What exactly is the `subs` argument of the `evalf` method of SymPy Expression for? Like `s.evalf(subs={...})`?

numerical value for an expression in sympy

Is there any method to display value of variable in the expression before evaluating it in sympy in Python?

sympy will not evaluate an expression to a numeric value

lambdified sympy expression returns incorrect result

Use variable into ${ } value expression

Comparing a Sympy expression with variable exponent to zero

Is a single constant value considered an expression?

Sympy evalf for real symbol

How to apply evalf() to an expression from symengine.py?

Set lookup variable to be the value of an expression

Assigning a predicate variable instead of a lambda expression

I want to compare a value to the result of an expression instead of executing the result of the expression

Sympy Collect() in trig expression

Sympy - Rename part of an expression

Find functions in sympy expression

Different sympy expression results

general expression substitution in sympy

From string to sympy expression

Sympy expression as ratio of polynomials

Expression simplification in SymPy

Partially factoring an expression in Sympy

Manipulating sympy expression trees

Get the operations of a sympy expression

Minimize a sympy expression

Simplification of expression for factorial by SymPy

sympy expression to symbols