cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

vector functions - error fix

LouP
12-Amethyst

vector functions - error fix

While perusing Richard's recent post "Hexagonal Packing(4).mcd," which contained Stuart's vector support functions, I saw one vector function - locate (x,v) - that I was about to write for myself. Loosely described, the function determines the effective index of an arbitrary value x within a given vector v. As the test value x is swept thru the various vector values, the returned index should step in unity increments. The actual behavior for one simple test is in the attachment, and does not show the expected behavior.

A second function, IndexOfNearest, behaves as expected, but is not what I was looking for.

I created the locate2 function for my own needs, but it may be useful for others wanting a similar function. This new fct. distinguishes among test values equal to vector values, test values which fall between vector values, and test values outside the range of the vector. It is straightforward to collapse the result into integer index ony functions.

I haven't as yet found any errors in the new routine, but test volunteers are encouraged to find bugs.

Lou
4 REPLIES 4

Thanks Lou,

The attached function explorer is very basic, adjust the number of adjacent on either or both sides. Not enough time to appreciate your work and the all box collapsed [Mathcad + PC !].

jmG
TomGutman
1-Visitor
(To:LouP)

Locate is just plain wrong. It's a nice binary search. But even as such it returns the wrong value -- it should return i or j (which must be equal at exit), not k. Further, for a value not in the table the return value is the index the value should have -- which is the index of the next higher value, not the next lower value as described.

A correct version of locate is in the attached. Note that logically the returned value for values past the last value should be the index of the last value, as that is the value that meets the stated conditions.
__________________
� � � � Tom Gutman

On 5/11/2010 12:19:46 PM, lpoulo wrote:
>While perusing Richard's
>recent post "Hexagonal
>Packing(4).mcd," which
>contained Stuart's vector
>support functions, I saw one
>vector function - locate (x,v)
>- that I was about to write
>for myself. Loosely described,
>the function determines the
>effective index of an
>arbitrary value x within a
>given vector v. As the test
>value x is swept thru the
>various vector values, the
>returned index should step in
>unity increments. The actual
>behavior for one simple test
>is in the attachment, and does
>not show the expected
>behavior.
>
>A second function,
>IndexOfNearest, behaves as
>expected, but is not what I
>was looking for.
>
>I created the locate2 function
>for my own needs, but it may
>be useful for others wanting a
>similar function. This new
>fct. distinguishes among test
>values equal to vector values,
>test values which fall between
>vector values, and test values
>outside the range of the
>vector. It is straightforward
>to collapse the result into
>integer index ony functions.
>
>I haven't as yet found any
>errors in the new routine, but
>test volunteers are encouraged
>to find bugs.
>
>Lou
_______________________________

Sorry Richard, I forgot to say "thanks" for the hexagonal packing.

Lou,

About that vector routine, many functionalities come out directly from Match(z, A, modifier). The function is built-in DAEP [Data Analysis Extension pack], quickly demonstrated. Often, it is necessary to have it in a more general way PWL [PieceWiseLinear] bisection. You will find two examples left in their complete accompanying full "Simplex" form. Because the "simplex" is another simple/double/triple integration method.
Example 1: ranges asymmetric 0 ...
Example 2: is symmetric [�] a ... b

Jean



... "locate" is a bit confusing as it looks.

Two supplements added:

1. The phi extractor
2. A real locate task [inspired from DAEP].

There is also the local-min/max 1d, 2d, clean/noisy data set, functions

jmG
Announcements

Top Tags