Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How-to: sum

Suppose I have defined a function f(x)=x^2 and a list x=[0,1,2,3,4]

Now I can calculate the product x[2]*f(x[2]). But: If I use the command

k=var('k') sum(x[k]*f(x[k]),k,0,4)

I will get the message: "TypeError: unable to convert x (=k) to an integer"

How can I realize such a summation?

click to hide/show revision 2
No.2 Revision

How-to: sum

Suppose I have defined a function

f(x)=x^2
f(x)=x^2

and a list x=[0,1,2,3,4]list

x=[0,1,2,3,4]

Now I can calculate the product x[2]*f(x[2]).

x[2]*f(x[2])

But: If I use the command

k=var('k')
sum(x[k]*f(x[k]),k,0,4)

sum(x[k]*f(x[k]),k,0,4)

I will get the message: "TypeError:

TypeError: unable to convert x (=k) to an integer"

integer

How can I realize such a summation?