Solved

Matrix in advanced perl programming oreilly

Posted on 2001-06-20
8
316 Views
Last Modified: 2012-06-27
Hi,
On page 28 of the book 'other matrix representations', number of element (8,4) in matrix of 10 rows and 5 colums is calculated as element 38, (7 * 5 + 3).

The formula i use to calculate this number =
E = (y-1)r + x
Where E = the element result i search,
r = rows of the matrix
searching element (x,y).

in the former example we get:
E = (4-1)*10 + 8.
E = 38.

Can anyone explain how the autor got to 7*5+3 ???

Thanks in advance(d perl programming)

50 pts. due to no real death importance, just questioning myself.
0
Comment
Question by:jbrugman
  • 5
  • 2
8 Comments
 
LVL 5

Expert Comment

by:marecs
ID: 6210185
E = (x-1)c + (y-1)

The elements are stored in the order (1,1) (1,2) ... (1,5) (2,1) and not (1,1) (2,1) as you have calculated. Your calculation also requires a (x-1) because element (1,1) is actually element 0
0
 
LVL 5

Expert Comment

by:dcgames
ID: 6210724
MARECS is correct. The formula in the example is for arrays with base ZERO (like perl) and stored in ROWS.

Other languages store arrays starting with 1, or store
in COLUMNS, or both, and the formula changes for each
of these cases.

Dave
0
 
LVL 5

Expert Comment

by:dcgames
ID: 6210725
MARECS is correct. The formula in the example is for arrays with base ZERO (like perl) and stored in ROWS.

Other languages store arrays starting with 1, or store
in COLUMNS, or both, and the formula changes for each
of these cases.

Dave
0
 
LVL 5

Expert Comment

by:dcgames
ID: 6210728
Dang. Double Click.. :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:jbrugman
ID: 6212981
E = (x-1)c + (y-1)
E = (8-1)5 + (4-1)
E = 38.

But then element (4,2) -> 14
E = (4-1)5 + (2-1)
E = 16
This one is not correct.
can you explain? the formula you gave came to my mind too.
0
 
LVL 4

Author Comment

by:jbrugman
ID: 6212993
as i draw both way matrixes, i sill came on 14, what wrong then?
0
 
LVL 5

Accepted Solution

by:
dcgames earned 50 total points
ID: 6215971
The problem here is with the x&y. If you have a matrix that is 10 by 5, then your x is in range 0 to 9 and the y is in range 0 to 4.

If x&y are already in range, you don't need -1. The formula becomes x*5+y

0,0 = 0*5+0 = 0;
0,1 = 0*5+1 = 1;
0,2 = 0*5+2 = 2;
0,3 = 0*5+3 = 3;
0,4 = 0*5+4 = 4;
1,0 = 1*5+0 = 5;
1,1 = 1*5+1 = 6;
1,2 = 1*5+2 = 7;
..
7,3 = 7*5+3 = 38;
..
8,4 = 8*5+4 = 44;
..
9,4 = 9*5+4 = 49;

See?

Dave
0
 
LVL 5

Expert Comment

by:dcgames
ID: 6215982
The same works for column stored arrays. The formulas are:

a) For row first, zero based: x * Rsize + y
b) For row first, one based:  (x-1)* Rsize + y - 1
c) For column first, zero based: y * Csize + x
d) For column first, one based: (y-1) * Csize + x - 1

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
collecting information 2 140
Perl Scripting from a shell script with if and for 4 83
Linux rename files by reordering dates in the file name 6 33
Perl string filter 5 74
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now