check if symbolic expression contains a variable

i like this post (click again to cancel)
1
i dont like this post (click again to cancel)

check if symbolic expression contains a given variable

Is there a function or method that tests a symbolic expression <type 'sage.symbolic.expression.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 gravatar image leonardo
11 2

updated May 05 '12

kcrisman gravatar image kcrisman
6614 13 66 149

2 Answers:

i like this answer (click again to cancel)
4
i dont like this answer (click again to cancel)

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

link

posted May 04 '12

Mike Hansen gravatar image Mike Hansen flag of United States
3675 19 43 81
i like this answer (click again to cancel)
2
i dont like this answer (click again to cancel)

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

link

posted May 04 '12

Jason Grout gravatar image Jason Grout
3185 7 27 71

updated May 04 '12

Thanks, Mike and Jason. Both methods work very nicely in my program.

leonardo (May 05 '12)

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: May 04 '12

Seen: 98 times

Last updated: May 04 '12

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.