Ask Your Question
0

Sage Math Cloud Plotting Error, ValueError: cannot convert x to int

asked 2015-12-09 09:58:40 +0200

Joshua Burkhart gravatar image

I'm using SageMathCloud to compute a summation

sum([.25^(100-i) * .75^(i) * binomial(100,i) for i in range(0, 63)])

0.00274614363169321

but am not able to plot it

plot(sum([.25^(100-i) * .75^(i) * binomial(100,i) for i in range(0, x)]),(x,1,63))

Error in lines 1-1
Traceback (most recent call last):
  File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "sage/symbolic/expression.pyx", line 1084, in sage.symbolic.expression.Expression.__int__ (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/expression.cpp:8329)
    raise ValueError("cannot convert %s to int" % self)
ValueError: cannot convert x to int

What am I doing wrong here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-12-09 15:24:20 +0200

calc314 gravatar image

Two issues here:

1) Sage is trying to evaluate the sum command as if it is a Python expression. So, to turn it into a function, you can do:

f=lambda x: add([.25^(100-i) * .75^(i) * binomial(100,i) for i in range(0, x)])

2) The plot command tries to plot at non-integer points, so your command will not plot. You can try the following:

pts=[point([x,f(x)]) for x in range(1,101)]
p=add(pts)
show(p)
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

Stats

Asked: 2015-12-09 09:58:40 +0200

Seen: 485 times

Last updated: Dec 09 '15