Question: transition matrix

I use transition matrix guess the next note of Happy birthday, but it tends to the same note in the final few notes

what is wrong?

why?

 

restart;
with(LinearAlgebra):
with(AudioTools):

MK := proc(f::numeric)
AudioTools:-Create(duration=0.5,rate=44100,x->evalhf(sin(x*2*Pi*f/44100))):
end proc:

C4 := 261.62:
D4 := 293.67:
E4 := 329.63:
F4 := 349.23:
G4 := 392.00:
A4 := 440.00:
B4 := 493.88:
C5 := 523.25:

initstate := Matrix([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,3,2,0,1,1],[0,0,2,0,0,0,0],[0,0,1,0,0,0,0],[0,0,1,0,1,0,0],[0,0,0,0,0,1,0]]);
statetemp := []:
for i from 1 to op(1,initstate)[1] do
if add(x, x in initstate[i]) = 0 then
statetemp := [op(statetemp), [0,0,0,0,0,0,0]]
else
statetemp := [op(statetemp), initstate[i]/add(x, x in initstate[i])]
end if:
od:
state := Matrix(7,7);
for i from 1 to op(1,initstate)[1] do
for j from 1 to op(1,initstate)[2] do
state(i,j) := statetemp[i][j];
od;
od;
state := MatrixMatrixMultiply(state, state);
member(max(state[3]),state,'pos');
member(max(state),state,'pos');
pos;
music := [A4,B4,C4,D4,E4,F4,G4];
song := [C4,C4,D4,C4,F4,E4,C4,C4,D4,C4,G4,F4,C4,C4]:
song := [op(song), music[pos[1]]];
for i from 1 to 10 do
state := MatrixMatrixMultiply(state, state);
member(max(state[pos[2]]),state,'pos');
member(max(state),state,'pos');
song := [op(song), music[pos[1]]];
od:
HappyBirthday:=Create(Vector(map(MK,song))):
Write("C:\\Users\\secret\\Documents\\HappyBirthday.wav",HappyBirthday);
 

Please Wait...