# check if symbolic expression contains a variable

 1 check if symbolic expression contains a given variable Is there a function or method that tests a symbolic expression to see if it contains a particular variable? For example to test y(x) == -3/(x^3 + 3c + 3x) to see if it contains the variable c. (I'm trying to write a a program to automatically plot the return value of the differential equation function desolve(), and it would help to be able to detect if the return expression contains the 'arbitrary constant' c.) asked May 04 '12 leonardo 15 ● 3 kcrisman 7437 ● 17 ● 76 ● 166

 4 You can also use the has() method for an expression: sage: var('x,c') sage: y(x)=-3/(x^3 + 3*c + 3*x) sage: y.has(c) True  example on aleph.sagemath.org posted May 04 '12 Mike Hansen 3840 ● 21 ● 46 ● 84
 2 Try the .variables() method for an expression: var('x,c') y(x)=-3/(x^3 + 3*c + 3*x) print y.variables() c in y.variables()  http://aleph.sagemath.org/?q=aefb061f-d758-499c-b4b3-b209efbf6240 posted May 04 '12 Jason Grout 3305 ● 7 ● 28 ● 74 Thanks, Mike and Jason. Both methods work very nicely in my program.leonardo (May 05 '12)

[hide preview]