On Sun, 30 Jan 2011 19:04:38 +0100
Francois Maltey <fmal...@nerim.fr> wrote:

> Hello,
> > I'd like to plot this function of x (latex code):
> >
> > x/2 + sum_{r=1}^n cos(rx)
> >
> > for some fixed n.
> //A//
> 
> First, sum is designed for formal sum, not for truncate sum even if 
> sometimes it's possible.
> But add is designed for these sums.
> 
> Second, expression doesn't evaluate the add(...) function.
> 
> Third, I think you want to change n0...
> 
> So I propose a function s (in Python), not a function coming from 
> expression.
> 
> k = var('k');
> 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))
> 
> //B//
> 
> You use Sage, not Maple. You must forget semicolon at the end.
> 
> //C//
> 
> After var('n'), it seems that your code is right in the last Sage.
> But I remain very careful about sum in order to get a1+a2+a3+...+a50.
> 

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)... 

renato

-- 
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