Ask Your Question

derivative of x^n

asked 2014-08-14 14:29:44 +0200

hildejk gravatar image

updated 2014-08-14 21:43:51 +0200

I am working with polynomials. I'd like to compute the symbolic derivative of a monomial with symbolic coefficients, that is something like


So that the output is


Is this possible?

Edit: My first try was of course to use:




but I get the error

TypeError: non-integral exponents not supported
edit retag flag offensive close merge delete


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.

dazedANDconfused gravatar imagedazedANDconfused ( 2014-08-14 18:10:52 +0200 )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.

hildejk gravatar imagehildejk ( 2014-08-14 21:39:40 +0200 )edit

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

Paul Graham gravatar imagePaul Graham ( 2014-08-16 07:02:10 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-08-16 17:19:09 +0200

dazedANDconfused gravatar image

updated 2014-08-16 17:20:50 +0200

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:


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.

edit flag offensive delete link more


thanks, I guess I am to newby.

hildejk gravatar imagehildejk ( 2014-08-19 08:27:40 +0200 )edit

answered 2014-08-14 21:58:28 +0200

ndomes gravatar image

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

f(x) = x^n
df = diff(f,x)
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2014-08-14 14:29:44 +0200

Seen: 564 times

Last updated: Aug 16 '14