Google Answers Logo
View Question
 
Q: Someone Familiar With Mathematica Software ( No Answer,   5 Comments )
Question  
Subject: Someone Familiar With Mathematica Software
Category: Computers > Software
Asked by: spud480-ga
List Price: $20.00
Posted: 30 Oct 2002 09:14 PST
Expires: 29 Nov 2002 09:14 PST
Question ID: 93205
I have(using Mathematica)created a list(Table)of numbers(ex.1000
3digit numbers)from strings of numbers. Can anyone tell me how to get
Mathematica to search and find any similar
(321-123-231---432-234)numbers in the list(if any)and sort the
answer,most numerous 1st in desending
order(123-321-231----432-234----673-736)?I use Windows Me and can
follow simple instructions but I am not trained in programming

Request for Question Clarification by rbnn-ga on 30 Oct 2002 12:12 PST
I do not understand what you are looking for here. 

You are saying a positive 3-digit decimal integer is "similar" to
another such 3-digit decimal integer if and only if the digits in the
first number are a permutation of the digits in the second, correct?
(A permutation is a rearrangement in the order). You want to find
equivalence classes of such numbers.

I am still not sure though what exactly you are trying to accomplish:
what does "most numerous 1st in desending order" mean? What is most
numerous - are you alluding to the number of times a number appears 
in the original list, or to the total number of numbers in the
original list that are members of a particular equivalence class?

If the numbers in the original list are 

List[111,111,111, 121,211] what would you like to see returned?
Answer  
There is no answer at this time.

Comments  
Subject: Re: Someone Familiar With Mathematica Software
From: al_kane-ga on 30 Oct 2002 16:37 PST
 
Hi... I've got a solution for you. 

Here's the following code that does what you ask:

  n3dig = 200;
  lo3d  = 100;
  hi3d  = 999;
  test1 = Table[Random[Integer, {lo3d, hi3d}], {i, 1, n3dig}];
  test2 = Table[IntegerDigits[test1[[i]]], {i, 1,
Dimensions[test1][[1]]}];
  test3 = Table[Sort[test2[[i]]], {i, 1, Dimensions[test1][[1]]}];
  test4 = Sort[test3];
  test5 = Union[test4];
  test6 = Table[Count[test4, test5[[i]]], {i, 1,
Dimensions[test5][[1]]}];
  test7 = Table[{test6[[i]], test5[[i]]}, {i, 1,
Dimensions[test6][[1]]}];
  answer = Sort[test7, (#1[[1]] > #2[[1]]) &];

I've broken each step into a separate line, so that you can ask me
about it if you need clarification. To run this code, you set the
number of 3-digit numbers through the n3dig parameter (I set it to
200). Then, it creates a table of random 3-digit integers that are
between 100 (lo3d) and 999 (hi3d). The next step breaks each 3-digit
integer into three 1-digit integers. After various manipulations, the
answer that you're interested is labeled 'answer', which is a table
listing the frequency of occurrence of similar 3-digit integers. Note,
it's easy to adapt this to 4- or higher-digit integers if you're
interested.
Subject: Re: Someone Familiar With Mathematica Software
From: spud480-ga on 31 Oct 2002 09:09 PST
 
I need some clarification. I form my string number by using ToString
etc,StringPosition etc,StringDrop etc. Then I create a Table that
partitions the number into groups of digits using StringTake
andStringLength etc.. This gives me a table of[for example]1000,3digit
numbers. This is where I am now. Do I enter your code at this point?
The RandomInteger part confuses me.I entered your code by itself and
received several error messages. Among them,
Set::write:Tag Times in 1o3d is Protected
Possible spelling error:new symbol name n3dig similar to existing
symbol ndig
Table:: iterb:Iterator{i,1,n3dig} does not have appropriate bounds
Subject: Re: Someone Familiar With Mathematica Software
From: al_kane-ga on 31 Oct 2002 11:27 PST
 
* Let's say that you have a table named "mytable" that contains
strings of numbers.

* First, use ToExpression[] on each of the elements in mytable. This
will convert the "strings" to integers. You can do this using:

  test1 = Table[ToExpression[mytable[[i]]],{i,1,Dimensions[mytable][[1]]}];

* Next, use the lines of the code I provided starting from "test2 =
...". This should give you your answer.
Subject: Re: Someone Familiar With Mathematica Software
From: spud480-ga on 01 Nov 2002 09:25 PST
 
It's not working. I entered the test1 code and I received error
messages. Among them-Part specification ToExpression[1] is longer than
depth of object-Iterator[i,1,Dimensions[1]does not have appropriate
bounds-Part 1 of{} does not exist.

PS-The table I start with contains no strings,it has already been
partitioned into 3 digit numbers[135-091-273-etc].
Subject: Re: Someone Familiar With Mathematica Software
From: al_kane-ga on 01 Nov 2002 10:01 PST
 
Well, I don't know what to say. It sounds like you have to get your
table into the correct format. Make sure it's setup like
{n1,n2,...,nm}, where n1 is your 1st 3-digit number, n2 is your 2nd
3-digit number, and nm is your last 3-digit number. If it's not, you
can use Flatten[] to get it into the correct format.


I will show you the output for all of the steps that I get for a
sample table called test1.

test1 = {454, 452, 343, 354, 354, 413, 314, 212, 453, 453};

test2 = {{4, 5, 4}, {4, 5, 2}, {3, 4, 3}, {3, 5, 4}, {3, 5, 4}, {4, 1,
3}, {3, 1, 4}, {2, 1, 2}, {4, 5, 3}, {4, 5, 3}}

test3 = {{4, 4, 5}, {2, 4, 5}, {3, 3, 4}, {3, 4, 5}, {3, 4, 5}, {1, 3,
4}, {1, 3, 4}, {1, 2, 2}, {3, 4, 5}, {3, 4, 5}}

test4 = {{1, 2, 2}, {1, 3, 4}, {1, 3, 4}, {2, 4, 5}, {3, 3, 4}, {3, 4,
5}, {3, 4, 5}, {3, 4, 5}, {3, 4, 5}, {4, 4, 5}}

test5 = {{1, 2, 2}, {1, 3, 4}, {2, 4, 5}, {3, 3, 4}, {3, 4, 5}, {4, 4,
5}}

test6 = {1, 2, 1, 1, 4, 1}

test7 = {{1, {1, 2, 2}}, {2, {1, 3, 4}}, {1, {2, 4, 5}}, {1, {3, 3,
4}}, {4, {3, 4, 5}}, {1, {4, 4, 5}}}

answer = {{4, {3, 4, 5}}, {2, {1, 3, 4}}, {1, {4, 4, 5}}, {1, {3, 3,
4}}, {1, {2, 4, 5}}, {1, {1, 2, 2}}}

As you see, answer contains the frequency of the combinations of
3-digit numbers from mytable. For instance, there are four 3-digit
numbers that contain the combination of 3, 4, and 5, while there are
only 2 instances of 3-digit numbers containing 1, 3, and 4.

Try starting with test1 above (copy and paste into Mathematica). Then,
run the initial code starting from test2. It should work as long as
you're using version 4.0 or higher (which has the Union function).

If this doesn't work, then try the Mathematica MathGroup help board
(http://forums.wolfram.com/mathgroup).

Cheers.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy