# Tag Info

29

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

29

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

20

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

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

This is a bug in version 8 and has been fixed in the development version. For now, you have to export the data and reconstruct the interpolation once you have read in the data. What follows is way to recover your data. You should not use this on a day to day basis. The idea is to recover your data and store the data and then reconstruct the interpolation. ...

14

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

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

14

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

14

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

12

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

11

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

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

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

10

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

10

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

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

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

9

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

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

8

You will have to make assumptions for the derivatives of your function at zero, unless your interpolating order is 1 (which is what @Szabolcs said in the comments). There is a package caled DifferentialEquationsInterpolatingFunctionAnatomy, which should help (it does, but is not enough). The way to really reconstruct your data is outlined in my answer to ...

8

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

8

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

8

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

7

Here's another possibility. First compute the derivatives (this should use formal symbols for safety, but I've used x,y,z here to avoid cluttering the code) intfd[x_, y_, z_] = D[intf[x, y, z], {{x, y, z}}]; then define the curl by intfcurl[x_, y_, z_] := Module[{q = intfd[x, y, z]}, {q[[2, 3]] - q[[3, 2]], q[[3, 1]] - q[[1, 3]], q[[1, 2]] - q[[2, ...

7

It seems that interpolation in two dimensions is desired. To do so, interpolate the x- and y-coordinates separately and plot the curve parametrically: Manipulate[ Module[{f = Interpolation[#, InterpolationOrder -> iorder] & /@ Transpose[Prepend[pts, {0, 0}]]}, ParametricPlot[Through[f[x]], {x, 1, Length[pts]+1}, PlotRange -> ...

7

In fact, halirutan and me already discussed this topic in the chat room only a few days ago, but he thought there should be an explicit question and answer here on main. So, here's my take... The key here is that the Fritsch-Carlson (the algorithm behind MATLAB's pchip()) and Steffen interpolation methods are both very easily modified to account for ...

7

BSplineCurve is based on BSplineFunction. But BSplineFunction is analytic expression - so you do not need to interpolate it - you can use it as a (parametric) function: g = BSplineFunction[points]; ParametricPlot[g[t], {t, 0, 1}] If you still need points - this will work with any step: bspts=Table[g[t], {t, 0, 1, .1}]

7

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

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