Ask Your Question
1

Sage refuses to evaluate summations...

asked 2021-07-18 00:10:31 +0200

Hyacinth gravatar image

updated 2021-07-18 10:36:40 +0200

slelievre gravatar image

I'm trying to define a function

g(x) = sum(frac(j*p/q), j, 0, x)

where p, q are pre-defined constants (say (p, q)=(33, 21)). Sage did not give any errors, but when I type g(10), I would get output symbolic expression sum(frac(11/7*j), j, 0, 10), which is different from the expected value 31/7.

How do I fix this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-07-18 10:37:21 +0200

slelievre gravatar image

updated 2021-07-18 10:44:46 +0200

There are two ways to get the value you want.

One is to define a Python function rather than a symbolic function.

Define p and q:

p, q = 33, 21

Define the function:

def g(x):
    return sum(frac(j*p/q) for j in range(x+1))

Use it:

sage: g(10)
31/7

The other way, with g defined as in the question (after declaring j as a symbolic variable) is to factor the result.

sage: j = SR.var('j')
sage: g(x) = sum(frac(j*p/q), j, 0, x)
sage: g(10).factor()
31/7
edit flag offensive delete link more

Comments

Thanks! I want to integrate this function, so a python function is probably not the best choice... Nonetheless, how is factor turning up here?

Hyacinth gravatar imageHyacinth ( 2021-07-18 16:49:44 +0200 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2021-07-18 00:10:31 +0200

Seen: 226 times

Last updated: Jul 18 '21