Trzecie laboratoria z modelowania matematycznego

Integrate[((Cos[x])^2),{x,0,2π}]

NestList[Mod[#+1,2π]&,0.5,100]
((Cos[#])^2)&/@%
Mean[%]

Mean[((Cos[#])^2)&/@NestList[Mod[#+1,2π]&,0.5,10000]]
Mean[Sin[#]&/@NestList[Mod[#+1,2π]&,0.5,10000]]

MarkovProcesses`

Maov

m={{0.340072750633301`,0.1432368189835306`,0.1774971860502392`,0.06967009620282885`,0.2695231481301003`},{0.13937502301071034`,0.35914252210656356`,0.2517756082283021`,0.10099733689132984`,0.1487095097630942`},{0.2125939720747229`,0.25794176812973785`,0.18574127189602707`,0.0024580241713623298`,0.3412649637281499`},{0.21851974394412318`,0.25590521773976593`,0.2578365352105264`,0.26509305229545943`,0.002645450810125064`},{0.00044815992877717225`,0.4031498660646585`,0.275480307580612`,0.03969901211621984`,0.28122265430973253`}}(*RandomReal[{0,1},{5,5}]*)
P=DiscreteMarkovProcess[{1,0,0,0,0},m]
Graph[P]
MarkovProcessProperties[P]

#/Total[#]&/@m

m

{1,0,0,0,0}.MatrixPower[m,1]
{1,0,0,0,0}.MatrixPower[m,2]

Animate[ListPlot[{1,0,0,0,0}.MatrixPower[m,nn],Joined->True,Mesh->Automatic],{nn,1,10,1}]

{1,0,0,0,0}.MatrixPower[m,10]
%.m
%-%%

{1,0,0,0,0}.MatrixPower[m,10]
Eigenvalues[m]
Eigensystem[Transpose[m]]

#/Total[#]&@{0.3368574427857851`,0.6321298294411221`,0.47950574531207685`,0.14662644907290373`,0.48529770926261406`}

szczur=DiscreteMarkovProcess[Table[If[k==1,1,0],{k,9}],{{0,1,0,1,0,0,0,0,0},
{1,0,1,0,1,0,0,0,0},
{0,0,1,0,0,0,0,0,0},
{1,0,0,0,1,0,1,0,0},
{0,1,0,1,0,1,0,1,0},
{0,0,1,0,1,0,0,0,1},
{0,0,0,0,0,0,1,0,0},
{0,0,0,0,1,0,1,0,1},
{0,0,0,0,0,1,0,1,0}}]
Graph[szczur]
MarkovProcessProperties[szczur]

mat={{0,(1/2),0,(1/2),0,0,0,0,0},{(1/3),0,(1/3),0,(1/3),0,0,0,0},{0,0,1,0,0,0,0,0,0},{(1/3),0,0,0,(1/3),0,(1/3),0,0},{0,(1/4),0,(1/4),0,(1/4),0,(1/4),0},{0,0,(1/3),0,(1/3),0,0,0,(1/3)},{0,0,0,0,0,0,1,0,0},{0,0,0,0,(1/3),0,(1/3),0,(1/3)},{0,0,0,0,0,(1/2),0,(1/2),0}}

mat//MatrixForm
MatrixForm[mat]

Table[If[k==1,1.,0.],{k,9}].MatrixPower[mat,500]
Chop[%]

Chop[Table[If[k==1,1.,0.],{k,9}].MatrixPower[mat,500]]
Chop[Table[If[k==2,1.,0.],{k,9}].MatrixPower[mat,500]]

Range[9]

Szczur[n_]:=RandomChoice[mat[[n]]->Range[9]]

NestList[Szczur,1,10]

Table[RandomChoice[mat[[1]]->Range[9]],{100}]

NestWhile

NestWhileList[Log,100,#>0&]//N

Table[NestWhile[Szczur,1,#≠3&&#≠7&],{1000}]
{Count[%,3],Count[%,7]}