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

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

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

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

abs()in the IF-condition## CODE

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

## RE: Problem with the rank of the matrix

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

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

and this

## CODE

## RE: Problem with the rank of the matrix

## RE: Problem with the rank of the matrix

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

## RE: Problem with the rank of the matrix

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

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.