Ask Your Question

Echo input in output.

asked 2017-03-15 09:05:02 +0200

anonymous user


updated 2017-03-17 06:54:24 +0200

I'm trying to use sage for documentation purposes, and I'm looking for a way to do some of the following.

Enter an equation f(x) = 2x Input f(2) or something close and get back f(2) = 4 instead of just 4.

I'm also looking for a way to input f(x) = 2x^2 Input diff(f(x),x), or an equivalent command and get f'(x) = 4x or d(f(x)/dx = 4x.

And an icing on the cake would being able to input integrate(f(x)dx) and return ∫f(x)dx => 4x + 15 + c

Bassically, if there is a way to the output more verbose, I'd love to know how.

I just started using Sage and I love it, thank you!

Edit: Thank you so much for the response @paulmasson Your word "typesetting" was new to me and helped me find some other posts. (This) seems to be my exact question: (This) one seemed to answer my question, but I don't know if I'm supposed to do this.

It gave me the idea of using f = function('f',x) == 2*x

I have no clue what function() is, but I'm working on it.

I have no idea how or why this is different from f(x) = 2*x, but it's pretty cool because now diff(f,x) evaulates to d(f(x)/dy = 2 However, it doesn't do diff(f) so well when there are two variables like f(x,y) = x^2 + y^2 .

I also really enjoyed this (one):

Edit: Links, and I'm sorry to the moderator that has to keep approving my edits. Thank you for your time. I promise this will be my last edit.

edit retag flag offensive close merge delete


I didn't realize myself that derivatives will now appear typeset if entered as fully symbolic functions, so you taught me something! As a former Mathematica user, I myself still don't quite get all the different ways Sage processes functions, symbolic or merely callable, so welcome to the club. That whole process could be made clearer.

P.S. if you put square brackets around the first URL in each pair and leave the parentheses around the second URL, they should the work like proper links for future readers.

paulmasson gravatar imagepaulmasson ( 2017-03-17 00:38:37 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-03-15 21:29:45 +0200

updated 2017-03-17 00:30:47 +0200

Typesetting for objects like derivatives, integrals and limits is not yet fully implemented in Sage, so the icing isn't available. You can however do something manually like this,

show( "f(2)=", f(2) )
show( "f'(x)=", diff(f(x),x) )
show( "∫f(x)dx=", integrate(f(x),x) )

which gives the sort of output you want.

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

1 follower


Asked: 2017-03-15 09:05:02 +0200

Seen: 407 times

Last updated: Mar 17 '17