0
$\begingroup$

I need to create two vector lists using table. This list contains random numbers that I want to be symmetric.

n = 10;
ξ[i_, j_] := 
  With[{z := RandomInteger[j - 1]}, 
   If[i != j, RandomChoice[{z/n, 1 - z/n} -> {1, 0}], 0]];
ρ[j_, i_] := ξ[i,j]
A = Table[
  a (Sum[ξ[i, j] Subscript[y, j] Boole[i != j], {j, 
      n}]) Subscript[x, i], {i, n}]
B = Table[
  b (Sum[ρ[j, i] Subscript[x, j] Boole[i != j], {j, 
      n}]) Subscript[y, i], {i, n}]

The numbers ξ[i_, j_] and ρ[j_, i_] are random values symmetric. For example, the random ξ[1,2]=ρ[2,1], ξ[1,3]=ρ[3,1_]... ξ[10,9]=ρ[9,10]

I believe the syntax error is in this line code ρ[j_, i_] := ξ[i, j].

Can anybody help me?

$\endgroup$
4
  • $\begingroup$ You probably mean \[Rho][i_, j_] := \[Xi][j, i] instead of \[Rho][j_, i_] := \[Xi][j, i]. But why don't you use Reverse (such as B = Reverse[A])? $\endgroup$
    – anderstood
    Mar 3, 2017 at 20:33
  • $\begingroup$ a big problem with your code, the xi (or whatever that letter is) is set delayed, thus gets a new random value every time you use it. the rho then has no symmetry relation to xi since it also gets newly randomly generated on each use. $\endgroup$
    – george2079
    Mar 3, 2017 at 21:51
  • 1
    $\begingroup$ Part of the issue here is that you haven't defined what is meant by "random". From what distribution do you want these matrices to be pulled? The simplest way to get a "random" symmetric matrix is to generate a matrix m with all random elements, and then form the matrix (m + Transpose@m)/2, but perhaps you're looking for something more specific? $\endgroup$
    – march
    Mar 3, 2017 at 23:52
  • $\begingroup$ @george2079 the expression ξ[i_, j_] := With[{z := RandomInteger[j - 1]}, If[i != j, RandomChoice[{z/n, 1 - z/n} -> {1, 0}], 0]]; gives random nubers for ξ[i_, j_] equal to zero or one. For example, ξ[1,2] = 1, ξ[1,3] = 1, ξ[1,4] = 0, ` ξ[1,5] = 0, ξ[1,6] = 1` ... I search values for ρ that are symmetric in relation to ξ. For instance: ρ[2,1]=ξ[1,2] = 1, ρ[3,1]=ξ[1,3] = 1, ρ[4,1]=ξ[1,4] = 0, ρ[5,1]=ξ[1,5] = 0, ρ[6,1]=ξ[1,6] = 1...Do you have any idea how I can do this operation? $\endgroup$
    – SAC
    Mar 4, 2017 at 1:48

2 Answers 2

2
$\begingroup$

I'd go with tables, like this:

n = 10
xi = Table[
   With[{z = RandomInteger[j - 1]}, (*notice `z` is not set
       delayed here (unless you want it to have
          two different random values in the RandomChoice) *)
    If[i != j, RandomChoice[{z/n, 1 - z/n} -> {1, 0}], 0]], {i, 
    n}, {j, n}];
rho = Transpose[xi];

then in the remainder of you code use xi[[i,j]] where you have xi[i,j] etc.

$\endgroup$
1
$\begingroup$

It's a bit tricky to figure out what you mean by them being both random and symmetric, since symmetry is not random. Perhaps the result you want can be had by memozing values for ξ?

n = 10;

mem : ξ[i_, j_] := mem =
  With[{z := RandomInteger[j - 1]}, 
    If[i != j, RandomChoice[{z/n, 1 - z/n} -> {1, 0}], 0]];

ρ[j_, i_] := ξ[i, j];

This can be shown to produce symmetric pairs in the manner you describe in a comment:

SeedRandom[0]  (* for a repeatable example *)

Array[ξ, {1, 10}] // Flatten

Array[ρ, {10, 1}] // Flatten
{0, 0, 0, 1, 0, 0, 1, 1, 1, 1}

{0, 0, 0, 1, 0, 0, 1, 1, 1, 1}

You would need to Clear[ξ] and re-evaluate this definition to reset the function and produce a new random value for each $i,j$ input pair.

$\endgroup$
2
  • $\begingroup$ I've tried to use your suggestion, but it's still not what I'm looking for. The expression ξ[i_, j_] := With[{z := RandomInteger[j - 1]}, If[i != j, RandomChoice[{z/n, 1 - z/n} -> {1, 0}], 0]]; gives random nubers for ξ[i_, j_] equal to zero or one. For example, ξ[1,2] = 1, ξ[1,3] = 1, ξ[1,4] = 0, ` ξ[1,5] = 0, ξ[1,6] = 1` ... I search values for ρ that are symmetric in relation to ξ. For instance: ρ[2,1]=ξ[1,2] = 1, ρ[3,1]=ξ[1,3] = 1, ρ[4,1]=ξ[1,4] = 0, ρ[5,1]=ξ[1,5] = 0, ρ[6,1]=ξ[1,6] = 1 $\endgroup$
    – SAC
    Mar 4, 2017 at 1:43
  • $\begingroup$ @SAC Please see the example I added to my answer. I do believe my method produces the result that you describe. $\endgroup$
    – Mr.Wizard
    Mar 4, 2017 at 2:48

Your Answer

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

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