Plotting a Line in TikZ: Investigating Unexpected Behavior

In summary, the conversation discusses plotting a line in TikZ and the issue of the largest zero being plotted incorrectly. The cause is attributed to incremental error and the solution involves adjusting the precision of the numbers used in the calculation.
  • #1
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: 635
Physics news on Phys.org
  • #2
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?
 
  • #3
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.
 
  • #4
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.
 
  • #5
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?
 
  • #6
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.
 
  • #7
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 jedishrfu

Related to Plotting a Line in TikZ: Investigating Unexpected Behavior

1. What is TikZ and how does it relate to plotting a line?

TikZ is a powerful graphics package for LaTeX that allows for the creation of high-quality diagrams and plots. It includes a wide range of tools and features for drawing lines, shapes, and other elements, making it ideal for plotting data and investigating unexpected behavior.

2. How do I plot a line in TikZ?

To plot a line in TikZ, you will need to use the \draw command, which allows you to specify the starting and ending coordinates of the line. You can also add additional options, such as line color, thickness, and style, to customize the appearance of the line.

3. What do you mean by "unexpected behavior" in relation to plotting a line?

Unexpected behavior refers to any discrepancies or inconsistencies in the plotted line that are not in line with the expected results. This could include gaps, jumps, or incorrect slopes in the line, which may be caused by errors in the data or in the plotting process.

4. How can I investigate unexpected behavior in my plotted line?

To investigate unexpected behavior, you can use the various tools and features available in TikZ, such as the \fill command to highlight specific areas of the line, or the \node command to add labels or annotations to the plot. You can also try adjusting the plotting parameters or double-checking your data to identify the source of the unexpected behavior.

5. Are there any common mistakes or pitfalls when plotting a line in TikZ?

Yes, some common mistakes when plotting a line in TikZ include using incorrect coordinates, forgetting to specify options for the line, or not properly formatting the data. It is also important to ensure that the scale of the plot is appropriate for the data being plotted to avoid any misleading or incorrect results.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
750
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
41
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
984
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
896
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
986
Back
Top