×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Problem with the rank of the matrix

## Problem with the rank of the matrix

(OP)
thread214-1724643: Problem with the rank of the matrix

Referring to previous post regarding the calculation of rank of the matrix. I can successfully call the function DGESVD and used the suggested code as stated in the last post.

When I computed the matrix ( 24 * 46 ) which only contains binary number. The result is computed as follows:

1 3.64607217729591
2 3.11579149211648
3 2.91200000461928
4 2.83459107977961
5 2.68999404785583
6 2.63985870332852
7 2.53258922551712
8 2.28824561127074
9 2.15657793810757
10 2.07466293751602
11 2.00000000000000
12 1.71147369543826
13 1.66250775110981
14 1.65538411163519
15 1.37754379874545
16 1.22587722267226
17 0.911529570151319
18 0.874032048897643
19 0.494678447008250
20 6.045268993254451E-016
21 4.206043210176423E-016
22 2.807232732494245E-016
23 1.832673728789574E-016
24 1.198908543433525E-016
25 3.075086004790109E-016
26 2.026892056278003E-016
27 1.326887916710233E-016
28 1.214346864222148E-029
29 2.433781731624030E-016
30 1.175548892892689E-016
31 7.208199020880733E-017
32 9.370490339002574E-033
33 1.28834274428350
34 1.01863211799745
35 0.770903711971019
36 4.499908304387861E-016
37 3.451198625651696E-016
38 2.806044838432099E-016
39 2.373229207430789E-016
40 1.365710281383188E-016
41 9.182776887501775E-017
42 7.279931258765407E-017
43 1.573105791821282E-033
44 0.000000000000000E+000
45 2.368277042556670E-016
46 1.544118454433936E-303
Rank of the Matrix = 22

The rank of the matrix is incorrect. May I know how can I count the rank of the matrix from the above computed solution?

Thanks

### RE: Problem with the rank of the matrix

Hi happykaren100,

Look at the source of the RankOfMatrix

#### CODE

...
! The rank of the matrix is the number of singular values that are not zero
eps = 5e-10
write(*,*) 'epsilon = ', eps
rank = 0
do i=1, lds
if (S(i) .gt. eps) then
rank = rank + 1
end if
end do
... 
So in your case the program computed 46 singular values, but there were only 22 of them which are greater then eps = 5e-10. Other values are considered as zeroes.
If you change the value of eps - for example to eps = 5e-20 - you will get higher rank (maybe 41).

Btw.: How do you know that the computed rank is incorect, and what shoud be the correct rank ?

### RE: Problem with the rank of the matrix

Btw the singular values could be negative too, so use the abs() in the IF-condition

#### CODE

...
if (abs(S(i)) .gt. eps) then
... 

### RE: Problem with the rank of the matrix

(OP)
Maybe you can refer to the below computed solution :
1 3.48827114198402
2 3.37462191652958
3 3.23705539495131
4 3.03411736006571
5 2.96196709783348
6 2.74361201331799
7 2.60966697020932
8 2.55596974342836
9 2.53032104449351
10 2.30022345754932
11 2.00000000000000
12 1.94405360923112
13 1.84430232827725
14 1.76282280685099
15 1.51307861517484
16 1.25017201299784
17 0.839272436102465
18 0.759532157444624
19 8.021518784623458E-016
20 5.858785722368622E-016
21 3.449370106811100E-016
22 2.050368731147062E-016
23 1.324197652982660E-016
24 5.586780340707950E-017
25 2.63718576555846
26 2.61312592975275
27 2.41997806158875
28 2.14403159931951
29 2.09167143088485
30 2.00000000000000
31 2.00000000000000
32 2.00000000000000
33 1.68603132922330
34 1.59457382282132
35 1.41421356237310
36 1.08239220029239
37 0.839381387158556
38 0.785685364644069
39 8.158725229358065E-016
40 4.382174912616777E-016
41 3.576474791632983E-016
42 2.228497854650981E-016
43 4.924359873903050E-017
44 1.970684905047771E-017
45 3.641940413913593E+267
46 4.660479228605279E+267
47 3.449631794364175E-307
48 3.449434875201132E-307
49 0.000000000000000E+000
50 2.558113813159305E-317
51 2.558131599522556E-317
52 1.544117823703176E-303[/u]

This is the matrix of 24*52. From the theory, the rank should be equal to the min(24,52), ie. <=24
No matter how I set the limit of eps, the result is also incorrect.
What else can I do with the code??
Thanks!

### RE: Problem with the rank of the matrix

#### Quote (happykaren100)

This is the matrix of 24*52. From the theory, the rank should be equal to the min(24,52), ie. <=24
No matter how I set the limit of eps, the result is also incorrect.

And what about a matrix, where some rows are the linear dependent, i.e. some of them are the linear combinations of the other?

According to your theory when rank=min(m,n) then every 2 x 2 matrix should have the rank=2 and every 3 x 3 matrix should have rank=3.
But it's definitely not true - for example this matrix:

#### CODE

3 3
1 1 
has rank=1
and this

#### CODE

1 1 1
2 2 2
3 3 3 
has rank=1 too.

### RE: Problem with the rank of the matrix

(OP)
the rank should only have the maximum value of min(m,n). For example: the matrix of (24 x 52 ) should only have the maximum value of 24, ie rank <= 24.

### RE: Problem with the rank of the matrix

#### Quote (happykaren100)

For example: the matrix of (24 x 52 ) should only have the maximum value of 24, ie rank <= 24.
But in your first example you got for the matrix 24*46 the rank 22, i.e. <= 24 - so, how do you know that it shoulld be incorrect?

What rank did you get in your second example with the matrix of 24*52 ?

### RE: Problem with the rank of the matrix

(OP)
As I am dealing with problems with the concept of graph theory, I can only connect the graph from computed solutions if the rank is 22. For the first example, I can't connect the graph from the computed solutions, therefore the rank should not be 22.

For the second example, the rank of the matrix found depends on the setting of eps. However, as shown on the computed solution, there are more 24 values greater 0, which violates the theory that the rank should only have the maximum value of 24.

In fact, will there be any error/improvement in finding the computed solutions from the suggested codes?

### RE: Problem with the rank of the matrix

Yes the second result is incorrect. There are 2 singular values which goes to the infinity:
45 3.641940413913593E+267
46 4.660479228605279E+267
It seems to be an error somewhere in your program - maybe you didn't provide the parameters for the subroutine DGESVD properly. Read about the subroutines usage - for example here.
http://www.cs.ucdavis.edu/~bai/publications/baidem...

I suggest to test the computation first on smaller examples and if it will work, then go to the larger.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!