Ask Your Question
0

Plotting cos(x+2)cos(x)-cos(x+1)²

asked 13 years ago

anonymous user

Anonymous

Hello.

Why does sage fail to plot this function?

plot(cos(x+2)cos(x)-cos(x+1)cos(x+1),(x,-pi,pi))

Returns

IndexError: index out of bounds

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 13 years ago

Xaver gravatar image

There are two points to your question: 1)

cos(x+2)*cos(x)-cos(x+1)*cos(x+1)=-sin(1)^2   #i.e. a constant

(Actually one of the experts should kick in and tell us what to do to make sage simplify your expression to that. I am frequently having problems to force sage to simplify even the most trivial expressions. A tutorial on that would be nice...)

2) sage uses matplotlib to do the plotting of your expression. The automatic selection of a 'proper' y-axis extent of that can cause problems when the actual y-extent of your data is identically zero. So, do something like:

plot(cos(x+2)*cos(x)-cos(x+1)*cos(x+1),(-pi,pi),ymin=-sin(1)^2*1.1,ymax=-sin(1)^2*.9)

and you'll get: ... a nice straight line

Preview: (hide)
link

Comments

For your first point, try `f = cos(x+2)*cos(x)-cos(x+1)*cos(x+1)` and then `f.trig_reduce()`.

John Palmieri gravatar imageJohn Palmieri ( 13 years ago )
2

answered 13 years ago

In general, you need "*" to indicate multiplication: replace "cos(x+2) cos(x)" with "cos(x+2) * cos(x)", for example. In this particular example, there seems to be another issue, and it might be a bug. Try replacing "2" with "2.01" and it should plot okay.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 637 times

Last updated: Oct 16 '11