ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 19 Aug 2014 01:27:40 -0500derivative of x^nhttp://ask.sagemath.org/question/23779/derivative-of-xn/ I am working with polynomials. I'd like to compute the symbolic derivative of a monomial with symbolic coefficients, that is something like
derivative(x^n,x)
So that the output is
nx^(n-1)
Is this possible?
**Edit:** My first try was of course to use:
diff(x^n,x)
or
derivative(x^n,x)
but I get the error
TypeError: non-integral exponents not supported
Thu, 14 Aug 2014 07:29:44 -0500http://ask.sagemath.org/question/23779/derivative-of-xn/Comment by dazedANDconfused for <p>I am working with polynomials. I'd like to compute the symbolic derivative of a monomial with symbolic coefficients, that is something like</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>So that the output is </p>
<pre><code>nx^(n-1)
</code></pre>
<p>Is this possible?</p>
<p><strong>Edit:</strong> My first try was of course to use:</p>
<pre><code>diff(x^n,x)
</code></pre>
<p>or</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>but I get the error</p>
<pre><code>TypeError: non-integral exponents not supported
</code></pre>
http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23785#post-id-23785Yes. First, type: var('n')
This will tell Sage that n is a variable. Then type: diff(x^n,x)
Run those two lines and you will get the output you want.Thu, 14 Aug 2014 11:10:52 -0500http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23785#post-id-23785Comment by Paul Graham for <p>I am working with polynomials. I'd like to compute the symbolic derivative of a monomial with symbolic coefficients, that is something like</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>So that the output is </p>
<pre><code>nx^(n-1)
</code></pre>
<p>Is this possible?</p>
<p><strong>Edit:</strong> My first try was of course to use:</p>
<pre><code>diff(x^n,x)
</code></pre>
<p>or</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>but I get the error</p>
<pre><code>TypeError: non-integral exponents not supported
</code></pre>
http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23798#post-id-23798@hildejk , I was able to run what @ndomes suggested below without error, using sage 6.3.Sat, 16 Aug 2014 00:02:10 -0500http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23798#post-id-23798Comment by hildejk for <p>I am working with polynomials. I'd like to compute the symbolic derivative of a monomial with symbolic coefficients, that is something like</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>So that the output is </p>
<pre><code>nx^(n-1)
</code></pre>
<p>Is this possible?</p>
<p><strong>Edit:</strong> My first try was of course to use:</p>
<pre><code>diff(x^n,x)
</code></pre>
<p>or</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>but I get the error</p>
<pre><code>TypeError: non-integral exponents not supported
</code></pre>
http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23792#post-id-23792@dazedANDconfused : thanks, but that is the first thing I tried, as that method works with "number exponents". When I put the command I receive an error. I shall edit my question to reflect this.Thu, 14 Aug 2014 14:39:40 -0500http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23792#post-id-23792Answer by dazedANDconfused for <p>I am working with polynomials. I'd like to compute the symbolic derivative of a monomial with symbolic coefficients, that is something like</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>So that the output is </p>
<pre><code>nx^(n-1)
</code></pre>
<p>Is this possible?</p>
<p><strong>Edit:</strong> My first try was of course to use:</p>
<pre><code>diff(x^n,x)
</code></pre>
<p>or</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>but I get the error</p>
<pre><code>TypeError: non-integral exponents not supported
</code></pre>
http://ask.sagemath.org/question/23779/derivative-of-xn/?answer=23803#post-id-23803I'll continue my comment here so the code is clear. Go to a Sage cell server, such as [here](http://www.sagemath.org/eval.html) and copy paste the following code into the box:
var('n')
diff(x^n,x)
Press "Evaluate" and your output will be: nx^(n-1).
Your question indicates that you tried diff(x^n,x) without declaring var('n'). Sage assumes x is a variable but everything else must be declared as a variable. Sat, 16 Aug 2014 10:19:09 -0500http://ask.sagemath.org/question/23779/derivative-of-xn/?answer=23803#post-id-23803Comment by hildejk for <p>I'll continue my comment here so the code is clear. Go to a Sage cell server, such as <a href="http://www.sagemath.org/eval.html">here</a> and copy paste the following code into the box:</p>
<pre><code>var('n')
diff(x^n,x)
</code></pre>
<p>Press "Evaluate" and your output will be: nx^(n-1).
Your question indicates that you tried diff(x^n,x) without declaring var('n'). Sage assumes x is a variable but everything else must be declared as a variable. </p>
http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23829#post-id-23829thanks, I guess I am to newby.Tue, 19 Aug 2014 01:27:40 -0500http://ask.sagemath.org/question/23779/derivative-of-xn/?comment=23829#post-id-23829Answer by ndomes for <p>I am working with polynomials. I'd like to compute the symbolic derivative of a monomial with symbolic coefficients, that is something like</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>So that the output is </p>
<pre><code>nx^(n-1)
</code></pre>
<p>Is this possible?</p>
<p><strong>Edit:</strong> My first try was of course to use:</p>
<pre><code>diff(x^n,x)
</code></pre>
<p>or</p>
<pre><code>derivative(x^n,x)
</code></pre>
<p>but I get the error</p>
<pre><code>TypeError: non-integral exponents not supported
</code></pre>
http://ask.sagemath.org/question/23779/derivative-of-xn/?answer=23793#post-id-23793That's what dazedANDconfused suggested, don't know how you could get an error.
var('n')
f(x) = x^n
df = diff(f,x)
df Thu, 14 Aug 2014 14:58:28 -0500http://ask.sagemath.org/question/23779/derivative-of-xn/?answer=23793#post-id-23793