# How to generate random waves

I want to generate a set of $$N$$ random waves, where the wave vector and phase are random numbers, this is my code

 Nwaves = 3;
theta := 2*Pi*RandomReal[];
phi := ArcCos@RandomReal[{-1, 1}] ;
alpha :=  RandomReal[{0, 1}];
u = Sum[ Sin[ Cos[theta] Sin[phi]  x +  Sin[theta] Sin[phi]  y  +
Cos[theta] z + alpha], {Nwaves}]
v = Sum[-Cos[ Cos[theta] Sin[phi]  x +  Sin[theta] Sin[phi]  y  +
Cos[theta] z + alpha], {Nwaves}]


This code changes the parameters for each N. And the problem needs to have the same values for cosine, sine, and alpha. And after each iteration they have to change as N varies.

• If you change both u and v to u:= and v:= you can get different waves. Each of the u and v are generated by different wave pararmeters as you have set theta and alpha to be RandomReal. – CasperYC Sep 22 '19 at 4:15
• The output has to be u1= sin(k1x +k1y +k1z +alpha1) v1=cos sin(k1x +k1y +k1z +alpha1)... etc . I can not realize how to solve this issue, maybe is so simple – irondonio Sep 22 '19 at 4:26

theta = Table[2*Pi*RandomReal[], {Nwaves}];
phi = Table[ArcCos@RandomReal[{-1, 1}], {Nwaves}];
alpha = Table[RandomReal[{0, 1}], {Nwaves}];
u = Sum[Sin[Cos[theta[[i]]] Sin[phi[[i]]] x + Sin[theta[[i]]] Sin[phi[[i]]] y +
Cos[theta[[i]]] z + alpha[[i]]], {i, Nwaves}]
v = Sum[-Cos[Cos[theta[[i]]] Sin[phi[[i]]] x + Sin[theta[[i]]] Sin[phi[[i]]] y +
Cos[theta[[i]]] z + alpha[[i]]], {i, Nwaves}];


gives, for example:

Sin[0.272676 - 0.73222 x + 0.547661 y - 0.800789 z] + Sin[0.604025 + 0.739488 x - 0.614812 y + 0.768951 z] + Sin[0.880726 + 0.834666 x + 0.186018 y + 0.976054 z]

-Cos[0.272676 - 0.73222 x + 0.547661 y - 0.800789 z] - Cos[0.604025 + 0.739488 x - 0.614812 y + 0.768951 z] - Cos[0.880726 + 0.834666 x + 0.186018 y + 0.976054 z]

If I understood it correctly, you can do something like

Nwaves = 3;
theta := 2*Pi*RandomReal[];
phi := ArcCos@RandomReal[{-1, 1}];
alpha := RandomReal[{0, 1}];
u := Sum[Sin[Cos[theta] Sin[phi] x + Sin[theta] Sin[phi] y + Cos[theta] z + alpha], {Nwaves}]
v := Sum[-Cos[Cos[theta] Sin[phi] x + Sin[theta] Sin[phi] y + Cos[theta] z + alpha], {Nwaves}]


Then to get 80 waves, you need

Table[{u, v}, {80}]


• This is not the solution and looking for, In this case, you've proposed the parameters changes since the wave vector and alpha sin ( ) and cos( ) and alpha. The solution needs to have each sin( ) and cos( ) need to take the same value for each iteration (same wave vector and phase) but they have to change randomly for each N. – irondonio Sep 22 '19 at 4:41