Ask Your Question

trivial problem with trying to graph 2 functions

asked 2016-07-14 08:41:45 -0500

Henry J gravatar image

updated 2016-07-14 09:35:14 -0500

kcrisman gravatar image

I'm very new to SageMath. I want to plot two functions on 1 graph. Here is the code

def draw1st_2nd_Order( k1=slider(0.01, 10, 0.1, 5, label = "k1 (s^-1)"), k2=slider(0.01, 10, 0.1, 5, label = "k2 (M^-1s^-1)" ) ):
    f(t) = 10*e^(-k1*t)
    g(t) = 10/(1+(10*k2*t))
    P1 = plot( f(t), 0, 10, ymin=0, ymax=10, color=’blue’, gridlines='minor') 
    P2 = plot( g(t), 0, 10, ymin=0, ymax=10, color='red')
    print "The x-axis is time in sec."
    print "The y-axis is [A] in mM."    

This is the error I get:

File "<ipython-input-1-8e804a2c9a22>", line 5
    P1 = plot( f(t), Integer(0), Integer(10), ymin=Integer(0), ymax=Integer(10), color=’blue’, gridlines='minor')
SyntaxError: invalid syntax

I'm trying to convert lots of Mathematica files to SageMath for an online biochem text. Once I get this example worked out, I can easily convert the rest. Any help would be greatly appreciated Henry J

edit retag flag offensive close merge delete


You may enjoy for a good free introductory Sage text relevant to your audience in terms of level.

kcrisman gravatar imagekcrisman ( 2016-07-14 09:37:51 -0500 )edit

If you are writing a text that has significant online Sage (or R, or whatever) interactive content and needs good technical formatting, I recommend a look at

kcrisman gravatar imagekcrisman ( 2016-07-14 09:39:54 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2016-07-14 09:37:15 -0500

kcrisman gravatar image

This is really subtle, and is no doubt related to a copy-paste issue.

You have color=’blue’. Notice how the quotes lean forward a bit. That is not a standard Python string delimiter; you need normal (ASCII) single or double quotes. Here you can see what you get if you use color='blue' as correct.

Looks good otherwise! Welcome to Sage! I'll put some other comments in the, well, comments.

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: 2016-07-14 08:41:45 -0500

Seen: 53 times

Last updated: Jul 14 '16