[Date Index]
[Thread Index]
[Author Index]
Interpolation bugs (feature?) - work arounds & efficiency for large n?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg23254] Interpolation bugs (feature?) - work arounds & efficiency for large n?
*From*: "Mark Van De Vyver" <mvyver at bigfoot.com>
*Date*: Sat, 29 Apr 2000 22:04:59 -0400 (EDT)
*Organization*: The University of Western Australia
*Sender*: owner-wri-mathgroup at wolfram.com
Hi all,
I've come across the following (to my mind) peculiar behaviour of
Interpolation. I've tried some work arounds BUT these don't give the same
answers, and it's the Interpolation answer I really would like to have ie f1
must be returned for x1, f2 for x2 etc Any hints, suggestiions, workarounds
much appreciated.
First, the manual says:
The data can have the forms {{x1,f1},{x2,f2},...} or {f1,f2,...} , where in
the second case, the xi are taken to have values 1, 2,....
I assumed it was implicit that the data must pre-sorted based on the x's?
But this seems not to be the case.
To make the problem concrete:
I've a list {{x1,f1},{x2,f2},{x3,f3}...} and possibly
{{x1,f1},{x1,f1},{x2,f2}...} or even {{x1,f1},{x1,f1},{x1,f1}...}
The second list is {y1,y2,y3..} and y's correspond to the x's where y can
take values larger and smaller than the x's. Based on the {x,f} list I'd
like to get a value for "f" that corresponds to the y's by interpolation.
At the end of this post there are sample data sets with unique xi's and
repeating xi's.
This problem 'seems' fine for Interpolation so far.
However feed in a list {{x1,f1},{x1,f1},...} and Interpolation refuses to
return anything.
If the whole list contains only this pair then surely returning f1 for any x
(possibly with a warning) is more sensible than doing nothing?
If you feed Interpolation a single pair it returns an InterpolatingFunction,
feed that function some other point for x and you get the initial f back
with an extrapolation warning. Which makes me think then that this logic is
consistent with accepting multiple x1's so long as they all correspond to
the same f1.
If the list is unsorted ie {{x1,f1},{x2,f2}...,{x1,f1},{x4,f4}...} then this
should not be a problem, and appears not to be. I understand that pairs
like {x1,f1} and {x1,f2}cannot be dealt with properly.
Anyway, in my case the list is sorted based on the xi's, smallest to
largest.
One other point is that Interpolation seems very, very memory hungry; try
the following after changing the length to 10000. For large n
InteropolatingPolynomial is not much of an option either.
tl = Table[{Random[Real, {0.00014305271373109637`, 0.0001824065009571021`}],
Random[Real, {4.578526153317412`, 14.578526153317412`}]}, {i, 1,
100}];
rl1 = (Interpolation[tl, InterpolationOrder -> 1][#]) & /@
tl[[All, 1]]; // Timing
rl2 = ((Fit[tl, {1, x}, x] /. x :> #)) & /@ tl[[All, 1]]; // Timing
Short[rl1,12]
Short[rl2,12]
The best work arounds I come up with for InterpolationOrder 1,2,3 are (these
also seem faster for (some) long lists).
data={{x1,f1},{x3,f3},{x2,f2},...} ie unsorted by x
Linear: Fit[data, { x}, x]
Quadratic: Fit[tvf[13], { x^2}, x]
Cubic: Fit[tvf[13], { x^3}, x]
Any suggestions/comments apprediated
TIA
Mark Van De Vyver
Department of Accounting and Finance
University of Western Australia
Hacket Drive
Nedlands 6907
Perth, WA
mailto:mvdv at bigfoot.com
http://www.bigfoot.com/~mvdv
+61 8 9345-1572 (after hrs - GMT+8)
+61 8 9380-2510 (direct)
+61 8 9380-2917 (general office)
+61 8 9380-1047 (fax)
(***** sample data *****)
data1={{0.000190977, 22.0061}, {0.000190977, 22.0061}, {0.000190977,
22.0061}, {0.000190977, 22.0061}, {0.000190977, 22.0061}, {0.000190977,
22.0061}, {0.000190977, 22.0061}, {0.000190977, 22.0061}, {0.000190977,
22.0061}, {0.000190977, 22.0061}, {0.000190977, 22.0061}, {0.000190977,
22.0061}, {0.000190977, 22.0061}, {0.000190977, 22.0061}, {0.000190977,
22.0061}, {0.000190977, 22.0061}, {0.000190977, 22.0061}, {0.000190977,
22.0061}, {0.000190977, 22.0061}, {0.000190977, 22.0061}};
data2={{0.000146671, 6.06234}, {0.000147534, 12.2968}, {0.000147594,
6.77044}, {0.000148851, 13.1081}, {0.000153825, 10.4588}, {0.000154663,
7.17763}, {0.000155005, 11.8468}, {0.000158904, 9.18477}, {0.000159485,
9.56509}, {0.000160189, 10.0885}, {0.000167443, 4.94182}, {0.000169354,
11.1956}, {0.000170394, 9.06161}, {0.000173242, 13.4714}, {0.000174629,
8.881}, {0.000174935, 11.2535}, {0.000175221, 10.6393}, {0.000175231,
9.30562}, {0.000175337, 14.1713}, {0.000176043, 4.94875}}
Prev by Date:
**Re: Vector Union**
Next by Date:
**Re: Re: Vector Union**
Previous by thread:
**Re: Q: PlotPoints has dramatic timing effect (and not trivialy)**
Next by thread:
**User's Manual?**
| |