Ask Your Question

random element in user defined class

asked 2017-02-20 00:09:04 -0600

Deepak Sarma gravatar image

Can I get random element of a user defined class of objects? For example if I define xyz(n) to generate all the $n \times n$ matrices with a particular property. How can I get a random matrix in my class xyz(5).

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-20 00:40:17 -0600

tmonteil gravatar image

updated 2017-02-20 00:41:37 -0600

You have to implement a random_element method by yourself, since sage will not discover which measure has to be sampled. If the property happens frequently among all matrices, you can use rejection the method: pick a random matrix (in the larger space) until you find one with the property and return that matrix.

edit flag offensive delete link more


Sorry, I don't have any idea how to implement it by myself. Can you please explain with an example? Any web link will be helpful. Thank you

Deepak Sarma gravatar imageDeepak Sarma ( 2017-03-08 01:36:03 -0600 )edit

It really depends on the property. Could you provide some examples of some xyz(n) that you would like to sample ?

tmonteil gravatar imagetmonteil ( 2017-04-10 22:24:11 -0600 )edit

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


Asked: 2017-02-20 00:09:04 -0600

Seen: 119 times

Last updated: Feb 20 '17