Macaulay2 » Documentation
Packages » DeterminantalRepresentations :: randomPSD
next | previous | forward | backward | up | index | toc

randomPSD -- constructs a random positive semidefinite matrix

Synopsis

Description

This method returns a random symmetric positive semidefinite real matrix of a given size $n$. The rank $r$ can also be specified: by default, the matrix will be full rank (with probability 1). An upper bound $s$ on the spectral radius can also be specified: by default, the matrix will have spectral radius $<= 1$.

i1 : randomPSD 5

o1 = | .585298   -.0545901 .0184505  -.0599728  -.149145   |
     | -.0545901 .761001   -.0118983 -.160458   -.02979    |
     | .0184505  -.0118983 .56512    .0605255   -.0250409  |
     | -.0599728 -.160458  .0605255  .609506    -.00367036 |
     | -.149145  -.02979   -.0250409 -.00367036 .761799    |

                5         5
o1 : Matrix RR    <-- RR
              53        53
i2 : A1 = randomPSD(5, 3)

o2 = | .0822059   .117626   -.109793  -.00518272 -.0292519 |
     | .117626    .168797   -.149976  -.0126384  -.0536067 |
     | -.109793   -.149976  .295902   -.204962   -.0805114 |
     | -.00518272 -.0126384 -.204962  .460442    -.0253618 |
     | -.0292519  -.0536067 -.0805114 -.0253618  .349651   |

                5         5
o2 : Matrix RR    <-- RR
              53        53
i3 : A2 = randomPSD(5, 3.0)

o3 = | .466141  -.549293  .0814037 .326059  -.171432  |
     | -.549293 2.32094   -.225548 -.826411 -.0874656 |
     | .0814037 -.225548  .538414  .404872  .190896   |
     | .326059  -.826411  .404872  .890458  .0658219  |
     | -.171432 -.0874656 .190896  .0658219 .577543   |

                5         5
o3 : Matrix RR    <-- RR
              53        53
i4 : (A1, A2)/eigenvectors -- note the difference!

o4 = (({.626892     }, | .162261  -.415623 .116326  -.582187 .446921 |),
       {.350611     }  | .218178  -.595049 .197553  .726969  .399931 |  
       {.379495     }  | -.620177 .364839  .146256  .297715  .673447 |  
       {1.83307e-18 }  | .733874  .580879  .109056  .153773  .331088 |  
       {-1.37383e-17}  | .05366   -.051451 -.956116 .142456  .277789 |  
     ------------------------------------------------------------------------
     ({2.93272}, | .248943  -.183226 .443654  .667494  -.511935  |))
      {.851128}  | -.856474 .297886  .368634  .197344  .0536749  |
      {.637309}  | .163236  .62407   .206671  -.464468 -.57048   |
      {.178755}  | .419929  .422352  .467183  .138583  .638603   |
      {.193582}  | .0386539 .556639  -.637422 .52969   -.0421905 |

o4 : Sequence
i5 : A3 = randomPSD(5, 3, 7.0)

o5 = | 1.20614   -.134804    -.0319069   -.60937  .0177087  |
     | -.134804  .16531      -.000970882 .12522   -.0189459 |
     | -.0319069 -.000970882 .0606769    -.175278 .226441   |
     | -.60937   .12522      -.175278    .932231  -.734734  |
     | .0177087  -.0189459   .226441     -.734734 .86079    |

                5         5
o5 : Matrix RR    <-- RR
              53        53
i6 : eigenvectors(A3, Hermitian => true)

o6 = ({-1.0368e-16}, | -.205148 .264997 .179599  -.74438  .548938   |)
      {3.70827e-16}  | .109985  -.17194 .97172   .0750933 -.0919877 |
      {.150772    }  | -.887915 -.4061  .0245115 .185606  .107882   |
      {1.08742    }  | -.386499 .601573 .0981496 -.153387 -.674958  |
      {1.98696    }  | -.089681 .61107  .115199  .618289  .472227   |

o6 : Sequence

Caveat

This method works by choosing the eigenvectors and eigenvalues independently randomly. The distribution on the (compact) set of PSD matrices of bounded spectral radius may not be uniform or statistically desirable (cf. Wishart distribution).

See also

Ways to use randomPSD :

For the programmer

The object randomPSD is a method function.