TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How can I work around this TikZ bug?

I am plotting points on function f(x)=1-x^2/2+x^4/16. Obviously f(x)=-f(x), but PGF does not think so.

rendering of the plot

    \draw[very thin, gray] (-2,0) grid (2,2);
    \draw[->] (-2.2,0) -- (2.2,0) node[right] {$x$};
    \draw[->] (0,-.2) -- (0,2.2) node[right] {$y$};
        \def\wExpr{1-.5*(\x^2)+(1/16.)*(\x^4)}     %%%%% <<<
        \foreach\x in {-1.9,-1.3,-.8,-.2,.4,.9,1.5,2.0}{
            \fill (\x,{\wExpr}) circle (2pt);

What am I missing?

PS: I am able to work around it with abs around the exponentiation, but why does this work?

share|improve this question

marked as duplicate by Jake, Joseph Wright Nov 30 '11 at 12:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 5 down vote accepted

use it this way:

share|improve this answer
Calling it a bug might be a bit harsh. I would assume that \foreach just performs string replacements, and -1.9^2 is -3.61, as it should be. – Mikael Öhman Nov 9 '11 at 14:55
ok, you are right, I'll fix the bug :-) – Herbert Nov 9 '11 at 15:04
It is a bug that's been around for some time. Matthew Leingang posted a fix for it at How Can I Work Around this TikZ Bug. – Jake Nov 9 '11 at 21:00
no, Mikael is right! -2^2=-4 is from the mathematical definition correct. if the minus should be part of the 2 we have to write (-2)^2=4 – Herbert Nov 9 '11 at 21:11
@Herbert: But x^2=4 for x=-2, and that's what the OP correctly expected. In the problem the variable should not be interpreted as a string of characters, but as an entity. – Jake Nov 9 '11 at 22:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.