# How to get a plot with more precision in the data points?

Working with other software called SolidWorks I was able to get a plot with a curve very close to my data points: I tried to get a plot as accurate as this, but using the Fit function, I could not get a plot as accurate.

Clear["Global*"] Is there something I need to modify or another method more effective than this?

• Attempting to fit 8 parameters (7 coefficients and an error variance) with 6 data points can not be warranted on any circumstances.
– JimB
Nov 28, 2018 at 17:37
• I'm voting to close this question as off-topic because fitting 8 parameters with just 6 data points is just plain wrong.
– JimB
Nov 28, 2018 at 17:38
• There are many ways to fit curves to data. Sometimes splines can be useful. What are you going to do with the curve after you get it? Nov 28, 2018 at 18:45

If you want to reproduce that graph exactly, add in the derivatives at each point when using the Interpolate function.

Clear["Global*"]
dados = {{{0}, 0, 0}, {{1}, 1000, 0}, {{2}, -750, 0}, {{3}, 250,
0}, {{4}, -1000, 0}, {{5}, 0, 0}};
Plot[
{x, 0, 5},
ImageSize -> 500,
Epilog -> {
Red,
PointSize[0.01],
}]


This should give you: which looks pretty close to your original graph.

However, I strongly caution making any assumptions based off the interpolation from 6 data points unless you have some other reason to believe that this shape is correct. As others have pointed out, your own answer attempts to use a high-order polynomial to fit the data. A 7-term polynomial will fit almost any (except something really ugly like a perfectly vertical line) 6 data points perfectly. Similarly, this interpolation will work for any 6 data points and doesn't necessarily mean the values in between are correct.

• +1. I think this is what the software is doing, but why it is using such a model is unexplained. (E.g. it might be that the data represent the local extrema, it which case, it's not a bad model.) Nov 28, 2018 at 21:00

Using halirutan an J.M.'s IPCUMonotonicInterpolation from this q/a:

Plot[IPCUMonotonicInterpolation[dados]@t, {t, 0, 5},
AspectRatio -> 1/GoldenRatio, GridLines -> Transpose[dados]] Clear["Global*"]
dados = {{0, 0}, {1, 1000}, {2, -750}, {3, 250}, {4, -1000}, {5, 0}};

(* {0, 5} *)

f = Interpolation[dados, InterpolationOrder -> 5];

Plot[f[x], {x, xmin, xmax}, Alternatively, use InterpolatingPolynomial

g[x_] = InterpolatingPolynomial[dados, x] // Simplify

(* 125/6 x (520 - 829 x + 450 x^2 - 101 x^3 + 8 x^4) *)

Plot[g[x], {x, xmin, xmax}, EDIT: Using Fit
g[x] == Fit[dados, {1, x, x^2, x^3, x^4, x^5}, x] //
`