# Tag Info

39

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 ...

37

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 *) ...

35

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 ...

28

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, ...

19

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

19

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 ...

18

[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 ...

17

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 ...

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

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: ...

13

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_,_]]:= ...

13

DeleteDuplicatesBy may be faster if used as follows: DeleteDuplicatesBy[{{{1, 2, 3}, 10}, {{1, 2, 3}, 20}, {{1, 2, 4}, 30}}, First] {{{1, 2, 3}, 10}, {{1, 2, 4}, 30}} For your second need: lis = GatherBy[{{{1, 2, 3}, 10}, {{1, 2, 3}, 20}, {{1, 2, 4}, 30}}, First]; mean = Mean /@ Map[Last, lis, {2}]; Then: Transpose[{lis[[All, 1, 1]], mean}] ...

12

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, ...

12

One thing you can do is fit a smooth function to the data, and draw the contour plot of that instead. Using the thin plate case of polyharmonic splines (see also this nice article by David Eberly), I get the following plot: Here is my code. Being fairly new to Mathematica, I am open to suggestions for improvement. data = {{875, 3375, 632}, {500, 4000, ...

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

Update: information below updated with values from version 10.0.0 I expect that if the InterpolationOrder is the same between functions it should be possible to merge them into one. If not Piecewise may be the best you can do. This is an incomplete answer but hopefully a useful signpost that may lead you to a solution. You can get the constituent parts ...

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

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

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 ... 11 Use NDSolve antiD = NDSolveValue[{f'[x] == Sqrt[1 + x^3], f[0] == 0}, f, {x, 0, 10}] Example usage: Plot[antiD[x], {x, 0, 10}] Alternatively... This works because this function can be antidifferentiated (by Mathematica). antiD = FunctionInterpolation[ Evaluate @ Integrate[Sqrt[1 + x^3], {x, 0, t}, Assumptions -> 0 < t < 10], {t, 0, ... 11 Major update, version 2.0 What changed: Is a different, more clever way of solving the problem. Overcomes most of the issues of previous versions. Problem summary: I will rephrase the problem in simplest terms. There exests a named curve called limacon (french, pronounced [ˈlɪməsɒn], means snail), described by a simple equation$r=a+b\cos{\theta}\$ in ...

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