0
$\begingroup$

I have the following code

a={{1,2},{4,3},{3,2}}
b={3,4,5};
x=SparseArray[a->Table[0,{i,Length[a]}]]
x=SparseArray[a->(Extract[x,a]+b)];

The above code fills the elements in (1,2),(4,3),(3,2) elements of the x matrix. and x is a 4by3 matrix. Now what i what is a matrix x such that x is a 4by4 matrix with symmetry. So x[[1,2]]=x[[2,1]] and so on. How can i do that without creating a separate 4by4 matrix?

$\endgroup$
1
  • $\begingroup$ It is customary to accept solutions that solved your problem by clicking the grey check mark next to that post. Please do that if the answer below answered your question! $\endgroup$
    – march
    Oct 19 '15 at 5:23
2
$\begingroup$
y = SparseArray[Thread[a -> b], Max@a {1, 1}]
(y + Transpose@y) // MatrixForm

Mathematica graphics

$\endgroup$

Your Answer

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

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