Quantcast
Channel: How to generate a matrix with certain conditions - Mathematica Stack Exchange
Browsing latest articles
Browse All 5 View Live

Answer by J. M.'s eventual burnout for How to generate a matrix with certain...

Since all the simple answers have been given, here is a SparseArray[] solution that may be useful if you want to generate large matrices without storing unneeded zero...

View Article



Answer by OkkesDulgerci for How to generate a matrix with certain conditions

You can use weight option in RandomChoicen = 5;m = 2;mat = RandomChoice[{1/m, 1 - 1/m} -> {1, 0}, {n, n}];(mat - DiagonalMatrix[Diagonal@mat]) // MatrixForm$\left(\begin{array}{ccccc} 0 & 1...

View Article

Answer by bill s for How to generate a matrix with certain conditions

Binary random variables are often modeled using the BernoulliDistribution. You can use the function RandomVariate to get a matrix of such variables.mat = RandomVariate[BernoulliDistribution[0.9], {5,...

View Article

Answer by Vsevolod A. for How to generate a matrix with certain conditions

m = 2;n = 5;rnd[x_] := If[RandomReal[{0, 1}] < 1/m, 1, 0];t = Table[rnd[x_]*(1 - KroneckerDelta[i, j]), {i, 1, n}, {j, 1, n}];t // MatrixForm

View Article

How to generate a matrix with certain conditions

I want to generate a $n \times n$ matrix.I want the diagonal entries to be all 0I want a random choice of matrix elements with 0 or 1.The probability of having a 1 as a matrix element is $1/m$ and the...

View Article

Browsing latest articles
Browse All 5 View Live




Latest Images