[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Matrix in advanced perl programming oreilly

Posted on 2001-06-20
8
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:dcgames
ID: 6210728
Dang. Double Click.. :)
0
 
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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…
Six Sigma Control Plans

649 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