       Re: programming competition Correction

• To: mathgroup at smc.vnet.net
• Subject: [mg4951] Re: [mg4904] programming competition Correction
• From: Allan Hayes <hay at haystack>
• Date: Mon, 7 Oct 1996 02:02:17 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Please change line 6 in the code that I gave from
If[n<2, {#1},
to      If[n<1, {#1},

giving

linearInterpolate2[ li_List, m_ ] :=
Block[{},
Append[
Join@@Partition[ li, 2,1,
(  n=Floor[Sqrt[(#2-#1).(#2-#1)//N]/m];
If[n<1,
{#1},
Table[#1 + k #2, {k,0,n}]&[#1,(#2-#1)/(n+1)],

]
)&
],
Last[li]
]
];

(the error crept in because of changing from Ceiling to Floor)

I time it (and check it!) against the fastest code in  Xah Lee's
posting "[mg4900] Re: programming competition",  due to
espen.haslund at fys.uio.no (Espen Haslund):

linearInterpolateEH2[ li_List, maxLength_ ]:=
Module[{p1, p2, n},
Append[Join @@ Table[{p1, p2} = li[[{i, i+1}]];
n = Max[Ceiling[Sqrt[#.#]&[N[p2-p1]]/maxLength],1];
Table[p1+(p2-p1)j,{j,0,1-.5/n,1./n}],
{i,1,Length[li]-1}], Last[li] ]
]

li = Table[{Random[], Random[]}, {1000}];
maxLength = .1;

a4 = Timing@ linearInterpolateEH2[ li, maxLength];
a5 = Timing@ linearInterpolate2[ li, maxLength];

First /@ {a4,a5}

SameQ@@ Last /@ SetPrecision[{a4,a5},5]

{21.3 Second, 14.8333 Second}

True

Allan Hayes
hay at haystack.demon.co.uk
URL:haystack.demon.co.uk

==== [MESSAGE SEPARATOR] ====

```

• Prev by Date: Integration Conundrum
• Next by Date: Re: help!! Plot3D of ellipsoid
• Previous by thread: Integration Conundrum
• Next by thread: Re:programming competition Correction