Tag Info

Hot answers tagged interpolation

38

Interpolation function methods Interpolation supports two methods: Hermite interpolation (default, or Method->"Hermite") B-spline interpolation (Method->"Spline") Hermite method I really can't find any good reference to Hermite method within Mathematica's documentation. Instead, I recommend you to take a look at this Wikipedia article. The ...

32

Let me elaborate on @stevenvh's answer using Splines instead of Interpolation. The danger of using f'[0] is that the built-in interpolation requires that the (Hermite) polynomials go through each data points. Now if you data is noiseless that's fine, but if your data is noisy, the derivative of the interpolation will be all the more noisy (as a rule its ...

29

From inspection, some investigation and ruebenko's help, what I've found so far is that InterpolatingFunction has the following underlying structure: InterpolatingFunction[ domain, (* or min/max of grid for each dimension *) List[ version, (* 3 in Mathematica 7, 4 from 8 onwards *) ...

24

So, what is the best way to join points in Mathematica? There is no one "best way" (not only in Mathematica, but in general); an interpolation scheme that behaves nicely for data set A might be a crapshoot when applied to data set B. It depends on the configuration of your points, and impositions you have on the interpolant (e.g. $C^1$/$C^2$ continuity, ...

18

It does seem that the options PeriodicInterpolation -> True and Method -> "Spline" are incompatible, so I'll give a method for implementing a genuine cubic periodic spline for curves. First, let's talk about parametrizing the curve. Eugene Lee, in this paper, introduced what is known as centripetal parametrization that can be used when one wants to ...

17

Like Chris says: data = {{0, 0.562}, {10, 0.523}, {20, 0.480}, {30, 0.438}, {40, 0.398}, {50, 0.357}, {60, 0.320}, {70, 0.285}, {80, 0.255}, {90, 0.230}, {100, 0.220}} f = Interpolation[data, InterpolationOrder -> 2] then f'[0] returns -0.0037

16

[I gave a similar response some time ago either in StackOverflow or MSE but now I cannot find it.] One way is to track the solution to the ODE that runs over the difference if[x]-g[x]. Use WhenEvent to record axis crossings. This will find all zeros that do not have multiplicity (that is, that cross transversally). Should also find any that are of odd ...

15

Mathematica's interpolation function, Interpolation, works on multidimensional data. For example, data = Flatten[Table[{x, y, x^2 + y^2}, {x, -10, 10}, {y, -10, 10}], 1]; int = Interpolation[data]; Then, you can extract the values for values between the data points: int[1.1, 1.1] (* ==> 2.42 *) And Plot3D, or whatever else you want. Plot3D[int[x, ...

15

May not turn out to be a very general method but here I will adapt the Interpolation function of MMA in a way so that smoother result can be obtained for your specific data set. Interpolation vs. ListLinePlot First lets see how the default Interpolation behaves compared to the interpolating function used when we call ListLinePlot with same interpolation ...

14

You have to provide the values of independent variable. Assuming that the points correspond to equidistant values of an independent variable, you can do this, for example: int = Interpolation[ Select[Transpose[{Range[Length[data]], data}], NumericQ[Last[#]] &], InterpolationOrder -> 1 ] Of course, you may wish to scale the independent ...

13

Interpolation. Let's create some 100x3 data matrix, coloumns representing x, y and f(x,y), covering the domain from [1,10], sampled at the integers for both x and y data = Join[Tuples[{Range[10], Range[10]}], RandomReal[20, {100, 1}], 2]; Now, I have to apply Interpolation to the data, but after grouping it as a list of {{x, y}, f[x,y]} values f = ...

13

This is fixed in version 9. This came up on MathGroup before. Since it hasn't been fixed for so long, I wasn't sure if it was really a bug, so I did some spelunking (and some speculation) today to find out what's happening. To jump to the end: I think it's a bug. First, let's see what arguments does LogLinearPlot really pass to the function: ...

12

NIntegrate has many advanced options that let you control which algorithms and strategies it will use. I'm quite sure that you can find a set of options that will make NIntegrate work well enough for the desired task, but of course these numerical algorithms will never be quite as fast and precise as an exact solution, which your sums and Integrates results ...

12

The question made me wonder about zero-order interpolations. It's hardly clear which is the right way. When I tried to figure out why ListLinePlot would use a different Interpolation, I noticed it didn't seem to use an Interpolation for orders 0 or 1 at all, but did it the simple way which you might use by hand: connect the dots. This was probably done ...

12

This is a straightforward application of FindClusters: ListPlot@FindClusters[#, 2] & /@ Transpose@PairSet // GraphicsRow See the DistanceFunction and Method options to further fine tune your clustering or use a different metric.

12

Your data seems to be composed of two components: An offset for each x-location (or an offset-function of x) and a density relative to that offset. If you had either of the two, estimating the other would be easy. Right so far? One common solution for this kind of problem is the EM algorithm. Basically, you start with some estimate for one variable (e.g. ...

12

Edit Applying @Kuba's y-rescaling trick works here as well, just pass the rescaling through the DistanceFunction option tour2 = FindShortestTour[data, DistanceFunction -> (EuclideanDistance[#1 {1, 30}, #2 {1, 30}] &)]; ListLinePlot[data[[tour2[[2]]]], Epilog -> {PointSize@0.01, Red, Point /@ data}] Here's as close as I can come with ...

11

Here's a somewhat complete implementation of Shoemake's spherical linear interpolation that functions completely analogously to Interpolation[] and InterpolatingFunction[]. As already noted, much of the slowness is due to your use of a sequential search. In any event, if you prefer, you could use the built-in interpolation as suggested in the other answer, ...

11

t = Table[{x, Sin[x]}, {x, 0, Pi, .01}]; 1/2 Total[((#[[2, 1]] - #[[1, 1]]) (#[[2, 2]] + #[[1, 2]])) & /@ Partition[t, 2, 1]] (* -> 1.99998 *) Perhaps better 1/2 Total[Differences[t[[All, 1]]] ListCorrelate[{1, 1}, t[[All, 2]]]] They are just $$\int_a^b f(x)\,dx\approx\frac12\sum_{k=1}^N (x_{k+1}-x_k)(f(x_{k+1})+f(x_k))$$ Edit Just for fun, ...

11

Following the method on the wikipedia page mentioned in the comments, I came up with this interp[pts_] := Module[{delta, mlst, zeropos, tau, h00, h01, h10, h11}, delta = #2/#1 & @@@ Differences[pts]; mlst = Flatten[{delta[[1]], MovingAverage[delta, 2], delta[[-1]]}]; tau = Min[#, 1] & /@ (3 delta/Sqrt[(Most[mlst]^2 + Rest[mlst]^2)]); tau ...

11

One can look at the paper here. However, from the Wolfram Library Archive, I got this ready-made code that needed only the CompilationTarget -> "C" part to modernize: StinemanInterpolatingFunction::dmval= "Input value lies outside domain of the interpolating function."; Format[StinemanInterpolatingFunction[range_,_]]:= ...

11

When I told you that this was not possible, I was wrong. My understanding is that you have points $(x_1, y_1), (x_2, y_2), ..., (x_n, y_n)$ through which you construct an interpolating function $f$. Now you need to add another point $(x_0, y_0)$, and construct a new interpolating function $f^*$ for which it is true that $f^*(x) = f(x)$ for all \$x \in [x_1, ...

11

You are talking about a list of 3D points and curve fitting. I therefore assume you want a function with a single parameter that describes a curve fitting through your set of points. I don't believe ListInterpolate can handle that. My alternative is the following. First, a set of 3D points: pts1 = Table[{Sin[t], Cos[t], Cos[t] Sin[t]}, {t, 0, 2 \[Pi], ...

11

I think Nearest does it, but I'm having trouble getting a good plot. data = RandomReal[1, {20, 3}]; func = Nearest[{#, #2} -> #3 & @@@ data]; Plot3D[func[{x, y}], {x, 0, 1}, {y, 0, 1}, PlotPoints -> 50, ColorFunction -> (Hue@#3 &)] For comparison: ListPlot3D[data, InterpolationOrder -> 0, PlotRange -> {0, 1}, ColorFunction ...

10

The code in Heike's answer is a bit long, but only because it does not exploit the fact that piecewise Hermite interpolation is already supported by Mathematica as Interpolation[]. Thus, here is a shorter way to implement Fritsch-Carlson monotonic cubic interpolation: fcint[data_] := Module[{del, slopes, tau}, del = #2/#1 & @@@ ...

10

You want to remove high-frequency noise while retaining the low-frequency signal. This is a job for a bandpass filter. A simple one is the MovingAverage, which you can apply like so: xsi = Interpolation[MovingAverage[data, 20]] Plot[{Derivative[1][xsi][t], Cos[t]}, {t, 0, 6.25}, PlotRange -> {-1.1, 1.1}]

9

Your question isn't very clear, but I think you need the Rescale function, especially its 3 argument form: Rescale[#, {1, 100}, {7, 20}] & /@ Range[1, 100, 5] // N (* Out[1]= {7., 7.65657, 8.31313, 8.9697, 9.62626, 10.2828, 10.9394, 11.596, 12.2525, 12.9091, 13.5657, 14.2222, 14.8788, 15.5354, 16.1919, 16.8485, 17.5051, 18.1616, 18.8182, 19.4747} ...

9

The main slow-down in your code is the determination of the value of pos, which currently takes 90% of the time. You don't need to process the whole array to find where your time value is located. J. M.’s proposal is to perform bisection, but I’d suggest to use Mathematica’s own tool for that: Interpolation! You have a function linking value of time and ...

9

You can use binary search with Compile. I failed inlining (Compile was complaining endlessly about types mismatch), so I included a binary search directly into Compile-d function. The code for binary search itself corresponds to the bsearchMin function from this answer. Clear[linterp]; linterp = Compile[{{lst, _Real, 2}, {pt, _Real}}, Module[{pos = ...

Only top voted, non community-wiki answers of a minimum length are eligible