Ask Your Question
1

sum with indexed variable

asked 2022-03-06 20:46:48 +0100

mahmood gravatar image

updated 2022-03-06 20:47:21 +0100

how do i write a symbolic expression/function to calculate this sum based on the given value of the variable 'k'?

image description

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-07 08:30:25 +0100

Emmanuel Charpentier gravatar image

updated 2022-03-07 18:26:07 +0100

Define a as a function of i. Possible use :

a = function("a")
d = var("d")
# I don't like to scratch Sage's predefined identifiers...
j, k = var("j, k", domain="integer")
S = sum(a(j)*d, j, 1, k+1)

EDIT : If you want to fiddle with output cosmetics, you might try :

a = function("a", nargs=1,
                   print_func=lambda self, *args: r"%s[%s]"%(self, args[0]),
                   print_latex_func=lambda self, *args: r"%s_{%s}"%(self, args[0]))
d = SR.var("d")
j, k = SR.var("j, k", domain="integer")

which allows for :

sage: sum(a(j)*d(), j, 0, k + 1)
d*sum(a[j], j, 0, k + 1)

and latex(sum(a(j)*d(), j, 0, k + 1)) gets interpreted as :

$$d {\sum_{j=0}^{k + 1} a_{j}}$$

HTH,

edit flag offensive delete link more

Comments

makes sense, tysm

mahmood gravatar imagemahmood ( 2022-03-07 11:39:15 +0100 )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

1 follower

Stats

Asked: 2022-03-06 20:46:48 +0100

Seen: 212 times

Last updated: Mar 07 '22