Hello Renato,
def s(x,n) :
    return x/2 + add (cos(k*x) for k in [1..n])

n0 = 5;
plot(s(x,n0),(x,0,pi))
Thanks for clarification and tips :) Just a last doubt: if I
understand correctly, add() wants as argument an array like for
example [1,2,7,5], but running  cos(k*x) for k in [1..n]
alone doesn't return such a thing (it gives error in fact)...
Yes !

And look at the results of

var('x,k,n')  # as usual

sum (cos(k*x),k,1,n) # a result from geometric and complex and trigonometric series
# look at the denominator in cos(x)-1.

sum (cos(k*x),k,1,n)(n=12)
# a quotient, I hope you don't try to get its value when cos(x)==1

add(cos(k*x) for k in [1..n])
# and get an error !

add(cos(k*x) for k in [1..12])
# get a long add + + + + +

(lambda n:add(cos(k*x) for k in [1..n]))(12)
# a little bad way to get ..+..+..+.. with a unknown n.
# but you can define it with a parameter n... in a function.

I hope you know the lambda function.

There are 3 kinds of functions in python/Sage :

1/ def fct (x): ... return result
as proc in Maple.

2/ lambda x : only one calculus without return
as -> in Maple (this is this tips I use here)

3/ fct(x)=x+33 or fct=x+33, and then fct(123) or fct(x=123)

This way is only possible for expressions :
sum is an operator over formal expression,
add doesn't accept formal parameter n in the loop.







--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to