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
Solved

Matrix in advanced perl programming oreilly

Posted on 2001-06-20
8
318 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

790 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