Plotting a Line in TikZ: Investigating Unexpected Behavior

  • Context: LaTeX 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Behavior Line Plotting
Click For Summary

Discussion Overview

The discussion revolves around an issue encountered while plotting a line in TikZ, specifically regarding unexpected behavior related to the precision of plotted zeros. Participants explore potential causes and solutions related to the rendering of mathematical functions in TikZ.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports that the largest zero of the plotted function is 24.0699, but TikZ appears to plot this zero inaccurately.
  • Another participant suggests that the issue might be related to incremental error and proposes experimenting with the number of samples used in the plot.
  • A different participant speculates that the problem could stem from TikZ's limitations in handling the precision of the numbers involved in the calculations.
  • One participant confirms that TikZ can only plot to a certain precision, specifically mentioning the limitation to the first five digits after the decimal point.
  • Another participant expresses interest in a workaround to improve precision in TikZ plots and speculates on a method involving scaling constants to fit within the precision limits.
  • A participant confirms the speculation about scaling constants and provides a modified code snippet that successfully plots the function with the desired precision.

Areas of Agreement / Disagreement

Participants generally agree on the limitations of TikZ regarding precision and the potential for workarounds, but the discussion includes varying opinions on the exact nature of the problem and the effectiveness of proposed solutions.

Contextual Notes

There are unresolved questions regarding the impact of precision on the plotting of mathematical functions in TikZ, and the discussion does not reach a consensus on the best approach to mitigate these issues.

member 428835
Hi PF!

I'm plotting a line in TikZ using the following code

Code:
\draw[domain=0:25,samples=100,color=blue,variable=\x,line width=1.5] plot (\x,{0.9924686128641765 - 0.023406305144575135*\x - 
 0.0006942621866861979*\x^2 - .000001925581045950128*\x^3});

The largest zero is 24.0699 but latex is plotting that zero much larger. I've attached a picture so you can see what I'm referring to. Any ideas as to why this is happening?
 

Attachments

  • Screen Shot 2016-05-19 at 11.05.15 AM.png
    Screen Shot 2016-05-19 at 11.05.15 AM.png
    3.2 KB · Views: 706
Physics news on Phys.org
Could it have something to do with incremental error?

What if you change the stepping to be more or less steps? and larger or smaller steps?
 
jedishrfu said:
Could it have something to do with incremental error?

What if you change the stepping to be more or less steps? and larger or smaller steps?

Thanks for replying! I changed the samples to 5, 10, 100 and 1000 and nothing makes this graph converge to it's true zero.
 
This may be a problem with latex. Perhaps it can't handle the precision of your numbers in doing the calculation.

I tried it in freemat (free MATLAB clone) and got this pic:

Screen Shot 2016-05-19 at 9.52.37 PM.png


which seems to hit the 24.0699 zero.
 
Yea, you're right, tikZ can only plot to so much precision. First 5 digits after the decimal. I believe there is a way to subvert this though; I'll post if anyone wants the solution?
 
Post the solution. We live in an asynchronous world where someone 5000 years from now will read your post and will want to know how you subversively tricked TikZ in giving up the answer.

My guess is you multiplied all the constants by some magic number so that they fall into the 5 digit realm and then had TikZ solve for it.
 
jedishrfu said:
My guess is you multiplied all the constants by some magic number so that they fall into the 5 digit realm and then had TikZ solve for it.

You're guess is spot on! Code is here
Code:
\draw[domain=0:25,samples=100,color=blue,variable=\x,line width=1.5] plot (\x,{0.9924686128641765 - 2.3406305144575135*(\x/100) - 6.942621866861979*(\x/100)^2 - 1.925581045950128*(\x/100)^3});

Thanks for taking the time to consider this!
 
  • Like
Likes   Reactions: jedishrfu

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 0 ·
Replies
0
Views
6K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K