0
$\begingroup$

I am trying to create an $ n \times n $ matrix, which has cosine terms. I would like to select the values of the arguments of cosine terms from a random set of values that I have generated. My code looks as follows:

angles = RandomChoice[ RandomReal[{0, 2 Pi}, 2], {2, 3}]

M = Table[If[i == j, 0, Cos[x[i] - x[j]]], {i, 3}, {j, 3}]
$\endgroup$
1
$\begingroup$

I think DistanceMatrix constructive here. Consider this:

DistanceMatrix[#, DistanceFunction -> Cos@*Subtract] - IdentityMatrix[Length[#]] & /@ angles
$\endgroup$
  • $\begingroup$ I am looking for a generation of a tridiagonal matrix, with off-diagonal terms as functions of x[i]'s like the ones from distance function you've used. $\endgroup$ – EverydayFoolish Jan 8 at 6:49

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.