0
$\begingroup$

I have a matrix

mat = {{Sqrt[(1 + a0 + a3)/2], (a1 - I a2)/Sqrt[2 (1 + a0 + a3)]}, {0, Sqrt[(1 + a0 - a3)/2 - (a1^2 + a2^2)/(2 (1 + a0 + a3))]}};

How can I randomly generate mat by choosing a0 a1 a2 and a4 randomly subjeceted to condition a0 + a1^2 + a2^2 + a3^2 <= 1?

$\endgroup$
1
  • $\begingroup$ It all depends on what distribution you want to draw the random numbers from. Could you please be more explicit on this point? $\endgroup$
    – Roman
    Jul 26, 2021 at 17:22

1 Answer 1

2
$\begingroup$
Clear["Global`*"]

(mat = {{Sqrt[(1 + a0 + a3)/2], (a1 - I a2)/Sqrt[2 (1 + a0 + a3)]}, {0, 
     Sqrt[(1 + a0 - a3)/2 - (a1^2 + a2^2)/(2 (1 + a0 + a3))]}});

Assuming that -1 <= a0, a1, a2, a3 <= 1

rgn = ImplicitRegion[
   a0 + a1^2 + a2^2 + a3^2 <= 1 && 
    And @@ Thread[-1 <= {a0, a1, a2, a3} <= 1], {a0, a1, a2, a3}];

SeedRandom[1234];

mat /. Thread[{a0, a1, a2, a3} -> RandomPoint[rgn]]

(* {{0. + 0.0949935 I, -0.460629 - 4.49785 I}, {0, 4.52495}} *)
$\endgroup$
5
  • $\begingroup$ Thanks, Bob. I was expecting different matrix elements every time I run the code. $\endgroup$
    – Zubin
    Jul 26, 2021 at 19:09
  • $\begingroup$ Each time you execute the last line mat /. Thread[{a0, a1, a2, a3} -> RandomPoint[rgn]] by itself, you will get a different result. If you are also executing SeedRandom[1234]; it reinitializes from the same starting point and repeats. $\endgroup$
    – Bob Hanlon
    Jul 26, 2021 at 19:15
  • $\begingroup$ Got it. Thanks a lot! $\endgroup$
    – Zubin
    Jul 26, 2021 at 19:17
  • $\begingroup$ Is it possible to do this process as: Let a1^2+a2^2+a3^2=a^2. Then start with a0=0, a=1 all the way to a0=1, a=0 and find all matrices in this range of parameters? Should I ask this as a separate question? $\endgroup$
    – Zubin
    Jul 26, 2021 at 19:22
  • $\begingroup$ Yes, ask a new question and explain in detail what you want. $\endgroup$
    – Bob Hanlon
    Jul 26, 2021 at 21:54

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.