Hi Renato!

I tried something a bit different

sage: reset()
sage: def s(x,n):^J    return x/2 + sum(cos(k*x),k,1,n)
....:
sage: var('x,n,k')
(x, n, k)
sage: plot(s(x,5), (x,0,2*pi))

and it worked!

Enjoy!

Dox

On Jan 30, 4:48 pm, Renato Budinich <renn...@gmail.com> 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. However I'm running into problems... as I understand it
> sage converts the sum of cosines in a sum of exponentials, but then somehow
> doesn't get real values (and thus can't plot the function in the plane).
> Below is the code and the error. Am I doing something wrong? I'm on sage
> 4.4.2
>
> renato
>
> k = var('k');
> s(x,n) = x/2 + sum(cos(k*x),k,1,n);
> n0 = 5;
> plot(s(x,n0),(x,0,pi));
>
> verbose 0 (3495: plot.py, generate_plot_points) WARNING: When plotting,
> failed to evaluate function at 200 points.
> verbose 0 (3495: plot.py, generate_plot_points) Last error message:
> 'can't convert complex to float; use abs(z)'

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