Ask Your Question

# derivative of x^n

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

edit retag close merge delete

## Comments

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

( 2014-08-14 11:10:52 -0500 )edit

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

( 2014-08-14 14:39:40 -0500 )edit

@hildejk , I was able to run what @ndomes suggested below without error, using sage 6.3.

( 2014-08-16 00:02:10 -0500 )edit

## 2 answers

Sort by ยป oldest newest most voted

I'll continue my comment here so the code is clear. Go to a Sage cell server, such as here 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.

more

## Comments

thanks, I guess I am to newby.

( 2014-08-19 01:27:40 -0500 )edit

That's what dazedANDconfused suggested, don't know how you could get an error.

var('n')
f(x) = x^n
df = diff(f,x)
df

more

## Your Answer

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

Add Answer

## Stats

Asked: 2014-08-14 07:29:44 -0500

Seen: 137 times

Last updated: Aug 16 '14