Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Generating special random matrices in sage

asked 0 years ago

sagequstions gravatar image

updated 0 years ago

Is there an easy way to generate a random n×n-matrix in Sage that is lower triangular with ones on the diagonal and the entries are all in QQ or ZZ(or the natural numbers)?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 0 years ago

Max Alekseyev gravatar image

Here is an example:

n = 5
Matrix(ZZ,n,n,lambda i,j: 1 if i==j else ZZ.random_element() if i>j else 0)
Preview: (hide)
link

Comments

Thank you, is there also a way to get only natural numbers instead of integers? I tried this, but it does not seem to work:

n = 14
PP = PositiveIntegers()
M=Matrix(PP,n,n,lambda i,j: 1 if i==j else PP.random_element() if i>j else 0)
sagequstions gravatar imagesagequstions ( 0 years ago )

You can use abs(ZZ.random_element()).

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 191 times

Last updated: Jan 28