0
$\begingroup$

I understand this question has been asked before but for some reason I can't get it to work also I'm new to stackexchage so I apologize if everything I write is not up to standards. That being While[procedure;test] In the code I'm currently working on I'm trying to make a matrix but only if it makes certain conditions. The Code as it currently stands is x=Table[RandomChoice[{1-alpha*E^(-1/Total[listA]),alpha,alpha*E^(-1/Total[listA]}->{-1,0,1}]*ListB[[i]]*ListB[[j]],{i,Length[ListB]},{j,Length[ListB]}] and I'm trying to make the code cycle through till it hits condition of Det[%]>0

$\endgroup$
3
  • 1
    $\begingroup$ Would it be possible to give the full code that you are using and what your are hoping for as an output? It is not too clear from your question? $\endgroup$
    – Dunlop
    Commented Nov 3, 2016 at 20:45
  • $\begingroup$ I'm trying to get a table where the Det is a positive number. both List A and list B are simple lists, there is nothing complicated about them. $\endgroup$
    – Wilco
    Commented Nov 3, 2016 at 20:53
  • 1
    $\begingroup$ Did you try While[x = Table[...]; Det[x] <= 0]? $\endgroup$ Commented Nov 3, 2016 at 21:27

1 Answer 1

2
$\begingroup$

I've just made up listA and listB:

listA = {1, 2, 3, 4, 5};
listB = {8, 7, 6, 5, 4}; alpha = 1; 
x := Table[RandomChoice[{1 - alpha*E^(-1/Total[listA]), alpha, 
      alpha*E^(-1/Total[listA])} -> {-1, 0, 1}]*listB[[i]]*
      listB[[j]], {i, Length[listB]}, {j, Length[listB]}]
While[m = x; Det[m] <= 0];
m

The final m is a matrix with positive Det. Because of the := definition, each time through the While, a different m is produced.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.