ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 09 Oct 2013 12:40:39 +0200Difference Between Constants and Variableshttps://ask.sagemath.org/question/10583/difference-between-constants-and-variables/Hello all. I'm working with variational calculus in sage and working with
complicate expression `F` of a lot of variables declared with `var`.
I used `var` to declare both variables and constants. My problem is that I have
to know the exact number of variables which some generic expression depends. By
this reason the member function `variables` of an expression does not work, i.e.,
it returs both variables and constants because them was declared with `var` function.
I'm wondering if there is some type of variable in sage that can act as a variable to construct an expression and don't be returned by the `variables` member function.Tue, 08 Oct 2013 12:33:02 +0200https://ask.sagemath.org/question/10583/difference-between-constants-and-variables/Comment by tmonteil for <p>Hello all. I'm working with variational calculus in sage and working with
complicate expression <code>F</code> of a lot of variables declared with <code>var</code>.
I used <code>var</code> to declare both variables and constants. My problem is that I have
to know the exact number of variables which some generic expression depends. By
this reason the member function <code>variables</code> of an expression does not work, i.e.,
it returs both variables and constants because them was declared with <code>var</code> function.
I'm wondering if there is some type of variable in sage that can act as a variable to construct an expression and don't be returned by the <code>variables</code> member function.</p>
https://ask.sagemath.org/question/10583/difference-between-constants-and-variables/?comment=16949#post-id-16949Could you please give an example of your expression, and tell us what you consider as variable and what you consider as constant in your example ?Tue, 08 Oct 2013 13:17:18 +0200https://ask.sagemath.org/question/10583/difference-between-constants-and-variables/?comment=16949#post-id-16949Answer by Kamel for <p>Hello all. I'm working with variational calculus in sage and working with
complicate expression <code>F</code> of a lot of variables declared with <code>var</code>.
I used <code>var</code> to declare both variables and constants. My problem is that I have
to know the exact number of variables which some generic expression depends. By
this reason the member function <code>variables</code> of an expression does not work, i.e.,
it returs both variables and constants because them was declared with <code>var</code> function.
I'm wondering if there is some type of variable in sage that can act as a variable to construct an expression and don't be returned by the <code>variables</code> member function.</p>
https://ask.sagemath.org/question/10583/difference-between-constants-and-variables/?answer=15532#post-id-15532I am not sur it answers the question :
def dependance(f):
dep = []
for var in variables:
if diff(f, var) != 0:
dep.append(var)
return dep
variables = var('x y z')
constants = var('A B C')
f = A*x + z^2/B + C
print dependance(f)
It returns `[x, z]`.Wed, 09 Oct 2013 10:14:34 +0200https://ask.sagemath.org/question/10583/difference-between-constants-and-variables/?answer=15532#post-id-15532Comment by Rafael Rojas for <p>I am not sur it answers the question :</p>
<pre><code>def dependance(f):
dep = []
for var in variables:
if diff(f, var) != 0:
dep.append(var)
return dep
variables = var('x y z')
constants = var('A B C')
f = A*x + z^2/B + C
print dependance(f)
</code></pre>
<p>It returns <code>[x, z]</code>.</p>
https://ask.sagemath.org/question/10583/difference-between-constants-and-variables/?comment=16945#post-id-16945Hello thaks for your answer, but that is not that I'm looking for, because in your method you have to set a priori the set list variables that you are using.Wed, 09 Oct 2013 12:40:39 +0200https://ask.sagemath.org/question/10583/difference-between-constants-and-variables/?comment=16945#post-id-16945