Ask Your Question
1

check if symbolic expression contains a variable

asked 2012-05-04 07:38:37 -0500

leonardo gravatar image

updated 2012-05-05 14:43:53 -0500

kcrisman gravatar image

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.)

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
4

answered 2012-05-04 12:55:00 -0500

Mike Hansen gravatar image

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

edit flag offensive delete link more

Comments

Is there an extension of this to functions? For example,

var('x,c')
function('f')
y(x) = -3/(x^3 + 3*c + 3*x) + f(c)
y.has(f(c))

? I am aware that this does not work as written, but I wonder if it is possible to extend it.

jupsal gravatar imagejupsal ( 2016-07-26 16:03:08 -0500 )edit
2

answered 2012-05-04 09:09:08 -0500

Jason Grout gravatar image

updated 2012-05-04 09:09:29 -0500

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...

edit flag offensive delete link more

Comments

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

leonardo gravatar imageleonardo ( 2012-05-05 07:02:59 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-04 07:38:37 -0500

Seen: 368 times

Last updated: May 04 '12