Tag Info

Hot answers tagged

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


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


10

Reason for incompatibility Yes, the doc shouldn't mention that it is fully compatible (that's an oversight...). BSplineFunction and BSplineCurve are fully compatible as far as I remember, but not BezierCurve and BezierFunction. The reason is that what BezierCurve is doing when it has more than d+1 control points for SplineDegree->d case is something ...


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


6

The warning is probably caused by premature evaluation (no pun intended). Because of the symbolic parameter t, s[t] evaluates to BSplineFunction[{{0.,1.}},<>][t] instead of a list of the form {x,y}, and only evaluates to numeric values when t assumes numeric values, too. The normal solution to this is to postpone the access of the y-variable [[2]] to ...


5

Taking your data in account from link you provided: data={{......}}; Find the model: model = Fit[data, x^# & /@ Range[0, 10], x] 20.2513 + 43.3389 x - 0.208411 x^2 + 0.193888 x^3 - 0.0341689 x^4 + 0.00281455 x^5 - 0.000131003 x^6 + 3.64629*10^-6 x^7 - 6.01724*10^-8 x^8 + 5.43205*10^-10 x^9 - 2.06702*10^-12 x^10 Verify it is more or less ...


4

Inverse of your function sampled and interpolated: g = InverseFunction@Interpolation[f /@ Range[0, 1, .1]] (* gives x for y = .6 *) g[.6] 0.35 Using FindRoot: FindRoot[second[f[t]] == .6, {t, .5}] {t -> 0.5} f[.5] {0.35, 0.6} Delaying evaluation: second[r_?(VectorQ[#, NumericQ] &)] := r[[2]] More general delay: ...


4

functions={bsplinefunc1,bsplinefunc2,bsplinefunc3}; Outer[#1[#2] &, functions, Range[0, 1, .1]] {{bsplinefunc1[0.], bsplinefunc1[0.1], bsplinefunc1[0.2], bsplinefunc1[0.3], bsplinefunc1[0.4], bsplinefunc1[0.5], bsplinefunc1[0.6], bsplinefunc1[0.7], bsplinefunc1[0.8], bsplinefunc1[0.9], bsplinefunc1[1.]}, {bsplinefunc2[0.], ...


3

I've used the method I'm about to show in this answer, but I suppose having it explicitly answer an interpolation question would be convenient. Starting with your points, testData = {{10, 10}, {10, 20}, {10, 25}, {10, 27}, {10, 28}, {9, 26}, {8, 25}, {5, 20}, {3, 1}}; we use Lee's centripetal parametrization scheme to generate corresponding ...


3

You can use Thread to apply a function to a list of arguments: Thread[bsplinefunc1[Range[0, 1, .1]]] {bsplinefunc1[0.], bsplinefunc1[0.1], bsplinefunc1[0.2], bsplinefunc1[0.3], bsplinefunc1[0.4], bsplinefunc1[0.5], bsplinefunc1[0.6], bsplinefunc1[0.7], bsplinefunc1[0.8], bsplinefunc1[0.9], bsplinefunc1[1.]} Now you can use Map to use the ...


3

Given the discussion, another approach you might want to consider would be to explicitly parameterize a function -- -- this way you get to control very precisely the form of the function and you can choose it to have a nice shape. As an added bonus, you can perhaps even find an analytical inverse, which greatly simplifies that part of the problem. For ...


3

If you absolutely must use B-splines, you can explicitly build the component functions that make up the B-spline, using the usual definitions: pts = {{0, 0}, {0.2, 0.7}, {1, 1}}; n = Min[Length[pts] - 1, 3]; (* B-spline degree *) m = Length[pts]; (* clamped uniform knots for B-spline *) knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n), ...


3

One approach is to turn your expression into functions. I give a few extra variations just to show what can be done and which you might find useful to learn. Here's the whole thing as a function (to be used, for example, in your Plot3D): Bfn = Evaluate[B /. {x -> #1, y -> #2}] &; Bfn[x, y] == B (* True *) Component functions can be ...


3

You can perform a replace: B[[2,3]]/.{x->-1,y->0} If you have a table of x and y values (call it xyvals) for given matrix elements then you could do: Table[B[[m,n]]/.{x->xyvals[[m,n,1]],y->xyvals[[m,n,2]]},{m,Length[B]},{n,Length[B[[1]]]}]


2

(1) I get a reasonable result interpolating separately. (2) I don't think your derivatives are doing what you expect. x1 = Interpolation[table[[All, 1]]]; y1 = Interpolation[table[[All, 2]]]; Show[ListPlot[table], ParametricPlot[{x1[t], y1[t]}, {t, 1, 21}], AspectRatio -> 1] Here are those derivatives. Plot[{x1'[t], y1'[t]}, {t, 0, 21}, ...


2

The data points you provided to BSplineFunction act as spline control points. Generally, splines do not go through them. The effect you want to achieve can be gotten using Interpolation: First plotting your function with a prettier aspect ratio: ParametricPlot[fFit[n], {n, 0, Length[testData] - 1}, Epilog -> Point[testData], AspectRatio -> ...


1

You probably want to map your function over a suitable list of points which fit the needs of the values you require. RandomInteger[{1, 10}, {20,2}]; f = BSplineFunction[%] Export["myfile.tsv",f[#]&/@ Range[0, 1, 0.1]] {{31., 76.}, {52.4823, 17.653}, {29.8387, 21.6133}, {47.3833, 64.0472}, {39.5027, 23.1}, {53.2083, 46.5833}, {58.128, ...


1

When manipulating B-splines in this manner, it is often convenient to fall back on the definitions. Luckily, since Mathematica supplies the function BSplineBasis[], using the definitions are easy: pts = {{0, 0}, {1, 1}, {2, -1}, {3, 0}, {4, -2}, {5, 1}}; n = 3; (* B-spline degree *) m = Length[pts]; (* clamped uniform knots for B-spline *) knots = ...


1

What about trying something like the following! pts = {{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}}; f = BSplineFunction[pts]; x[t_?NumericQ] := Module[{val}, val = f[t]; First@val]; y[t_?NumericQ] := Module[{val}, val = f[t]; Last@val]; Check it! Plot[{x[t], y[t]}, {t, 0, 1}, Frame -> True] Now the value you are looking for. nf[t_?NumericQ] := ...



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