Ask Your Question
1

check if symbolic expression contains a variable

asked 2012-05-04 14:38:37 +0100

leonardo gravatar image

updated 2012-05-05 21:43:53 +0100

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 19:55:00 +0100

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 23:03:08 +0100 )edit
2

answered 2012-05-04 16:09:08 +0100

Jason Grout gravatar image

updated 2012-05-04 16:09:29 +0100

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 14:02:59 +0100 )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 14:38:37 +0100

Seen: 1,700 times

Last updated: May 04 '12