I would like to write a function to generate a diagonally dominant matrix of random values. What I'm ultimately leading to is writing a code to implement the Jacobi method on this matrix in CUDA for a final project in one of my classes.

The problem is I don't really know how to do this. One idea I had was to create a random number generator and for each row of the matrix I'd check to see if the diagonally dominant criteria is satisfied. Otherwise I'd generate new numbers until it works. Then just repeat this for all the rows of the matrix. Now, I don't necessarily like this idea because for large matrices there is just no way of knowing how long it would take to generate such a matrix. Are there any known methods for creating such a matrix efficiently?

  • $\begingroup$ Do you have any specific distribution on diagonally dominant matrices you'd like to sample with respect to? $\endgroup$ – Yuval Filmus Nov 25 '14 at 1:35
  • $\begingroup$ No I don't...just any diagonally dominant matrix with random values. I was thinking if this becomes too difficult then what I'd do is create an nxn matrix and then just have the diagonal elements all be n and then the off diagonal elements can be set to 1. This will work although it's certainly not random. But for my purposes I think it should be ok. $\endgroup$ – user111707 Nov 25 '14 at 2:19
  • $\begingroup$ Note that programming questions are offtopic here. So while asking for algorithmic insight here is fine, you'll have to go elsewhere for CUDA-specific issues. $\endgroup$ – Raphael Nov 25 '14 at 7:28
  • $\begingroup$ If you want to compute just some diagonally dominant matrix that depends in some form of randomness, pick a random number for all off-diagonal elements and then set the elements on the diagonal appropriately (large enough). $\endgroup$ – A.Schulz Nov 25 '14 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.