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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Another way

MikeArmstrong
12-Amethyst

Another way

I have recently been building a selection of worksheets which show the different ways the collabs approach the problems I post. Well here�s another one if anyone has a bit of spare time.

I have come around this worksheet and the programs inside the sheet do exactly what is required.Calculate the number of times an element occurs in the matrix and displays the number and quanity in a display matrix.

As it can be seen the programs are horrible and I have been struggling to simplify or find find an alternative way.

Regards

Mike
15 REPLIES 15

On 1/27/2010 6:31:05 AM, Armo wrote:
== I have come around this worksheet and the programs inside the sheet do exactly what is required.Calculate the number of times an element occurs in the matrix and displays the number and quanity in a display matrix.

Attached.

Stuart

Superb, Stuart !

Thanks, Jean

Fantastic Stuart cheers.

Regards

Mike

Stuart would be kind enough to explain how the function works after the otherwise statement.

I think I understand how it works upto that point.

Regards

Mike

On 1/27/2010 12:06:35 PM, m_armstrong wrote:
== explain how the function works after the otherwise statement.
== I think I understand how it works upto that point.

Oh, I just type things at random until it works 🙂

Initialize the set vector, s, to 0

The construct 'for a ∈ v' iterates through every element of the array v in column order.

The if statement looks for a in s. match returns a vector with the index of a if it exists and generates an error if it doesn't; the on-error traps this error to give an alternative value of 0. i then contains either the index vector of a in s, or zero.

If it's zero (the IsScalar check) then it's a new member of the set, so it gets added to s and its corresponding counter, c, is set to 1.

If it's not zero, then j is set to the index and the corresponding count value is incremented.

Unfortunately, I can't remember why I added the second on-error statement. i0 should always be a scalar, thus making it unlikely that the on-error would ever be invoked ... however, I must have had some reason for putting it there. Removing the on-error trap has no effect on a standard array.

Strictly, the final sort is unnecessary, as the order of a set doesn't usually matter. However, most of the time it's preferable for human verification of the results or to speed up future searches. It could be removed if performance is an issue (which is unlikely for small arrays).

Stuart

FILTER CHAFF is an advanced project,
much different but damn interesting too.
NOT COMMON worth reading and save in the tool box.

jmG

A discussion about Stuart's setcount function, and the try to find 'another way'.

TODO: check what about complexes.

Regards. Alvaro.

Alvaro that is a fantastic piece of work.

Cheers for taking the time to look at it.

Regards

Mike

Right guys my limited brain is again struggling.

Can somebody explain how the IsScalar(a < on error match (a,s) works in Stuarts function.

Stuart did explain how his function works but I'm still struggling with this section.

Regards

Mike

On 1/28/2010 4:42:46 AM, m_armstrong wrote:
== Can somebody explain how the IsScalar(a < on error match (a,s) works in Stuarts function.

The first thing to note is that 'i ← 0 on error match(a,s)' is a complete statement that returns a result.

match(a,s) function tests for set membership. If a is already in s, then match returns it's index as a vector (← important bit!).

If a is not in s, then match throws an error, which the on-error statement handles by returning 0.

The result of the on-error-match statement is then assigned to i, with 0 (a scalar) if no match was found, and a vector if there was a match.

The IfScalar result (which applies to i) is true if there was no match, in which case setcount adds a to s. Otherwise, setcount increments a's count.

perhaps the rewritten setcount (in blue) will make it a little clearer?

Stuart

Cheers Stuart.

Think I have got my head round it now.

Better go and do some work!!!!!!

Regards

Mike

On 1/28/2010 4:42:46 AM, m_armstrong wrote:
== Can somebody explain how the IsScalar...
_________________________

IsScalar is one of many logical test.
The 4th cell is not a "scalar".



Did you read my two work sheets ?
For another use of "IsScalar".

jmG

... one step further:



jmG

Read more, means learn + (generally).
If you have red = version problem

jmG

Well explained cheers.

Regards

Mike
Announcements

Top Tags