How to get data points from plot?

Sorry for the confusion.In summary, the conversation discusses using NDSolve to find the solution to a differential equation and plotting it in Mathematica. The user is looking for a way to plot it in LaTeX using TikZ and receives helpful tips on how to do so. They also discuss a potential issue with an error message when using a specific piece of code.
  • #1
member 428835
Hi PF!

I used NDSolve to find the solution to a differential equation. I then plotted the solution in mathematica. However, I would like to be able to plot this in LaTex, specifically in TikZ. Can anyone help me here?

Thanks so much!
 
Physics news on Phys.org
  • #2
It is usually better to get a screen grab of your plot then embed in your LaTeX document as a graphic.
 
  • #3
joshmccraney said:
Hi PF!

I used NDSolve to find the solution to a differential equation. I then plotted the solution in mathematica. However, I would like to be able to plot this in LaTex, specifically in TikZ. Can anyone help me here?

Thanks so much!
The output of NDSolve is an InterpolatingFunction object. If the InterpolatingFunction object is named "f" then "f[[2]]" will produce a table containing the interpolation points.
 
  • #4
Dale said:
The output of NDSolve is an InterpolatingFunction object. If the InterpolatingFunction object is named "f" then "f[[2]]" will produce a table containing the interpolation points.
Hi Dale!

I have the following code
Code:
a=0;
s = NDSolve[{y[x] y''[x] + 2 (y'[x])^2 + x y'[x] - 2 a/(1 + a) y[x] ==
      0, y[1] == .0000000000001, y'[1] == -1/2}, y, {x, 0, 3/2}];
s[[2]]
but then I receive the response "Part 2 of..." followed by a long error message. Am I doing something wrong?

Thanks so much for your help!
 
  • #5
You could simply evaluate the interpolated function at the desired points:

Code:
Table[{x, Evaluate[y[x] /. s][[1]]}, {x, 0, 3/2, stepsize}]
or
Code:
Table[{x, s[[1, 1, 2]][x]}, {x, 0, 3/2, stepsize}]

The interpolating function itself is nested within [[1,1,2]] of the NDSolve output.
 
  • Like
Likes Dale and member 428835
  • #6
Very nice Fightfish! Inputting these into latex will be the worst, but this is a good way to get it done! Thanks!
 
  • #7
Actually, it took no time at all! Once copy-pasting mathematica's output, I used the "replace and find" search key and replaced "}" with ")" and the commas after the parenthesis with "to" etc. Thanks a ton!
 
  • #8
joshmccraney said:
then I receive the response "Part 2 of..." followed by a long error message. Am I doing something wrong?

Thanks so much for your help!
I like Fightfish's approach better. It turns out that my approach is not as simple as I has remembered.
 

1. How do I extract data points from a plot?

To extract data points from a plot, you can use a software or programming language specifically designed for data analysis, such as MATLAB, Python, or R. These tools have functions or methods that allow you to access and retrieve data points from a plot.

2. Can I manually extract data points from a plot?

Yes, you can manually extract data points from a plot by using a ruler or a protractor to measure the coordinates of each data point. However, this method can be time-consuming and less accurate compared to using software or programming languages.

3. How do I know which data points to extract from a plot?

In order to know which data points to extract from a plot, you need to have a clear understanding of the variables being plotted and their relationship. You can also use the scale or labels on the axes to determine the values of the data points.

4. Can I extract data points from a plot that is not in a straight line?

Yes, you can extract data points from a plot that is not in a straight line. In fact, many real-world data sets have curves or non-linear relationships. You can use curve-fitting techniques or advanced software to accurately extract data points from these types of plots.

5. Is it necessary to extract all data points from a plot?

No, it is not necessary to extract all data points from a plot. The number of data points you need to extract depends on the purpose of your analysis and the level of accuracy required. In some cases, a few data points may be enough to represent the overall trend of the data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
890
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
248
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
805
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
Back
Top