Last active
December 18, 2015 09:58
-
-
Save traversaro/5764756 to your computer and use it in GitHub Desktop.
physically consistent dynamical parameters subspaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N_PARTICLE = 4 | |
N_SIMULATIONS = 100000 | |
zeroth_moment = zeros(N_SIMULATIONS,1); | |
first_moment = zeros(N_SIMULATIONS,1); | |
second_moment = zeros(N_SIMULATIONS,1); | |
for i = 1:N_SIMULATIONS | |
m = 100*rand(N_PARTICLE,1); | |
x = 4*rand(N_PARTICLE,1)-2; %between -2 and 2 to have both | |
x2 = x.*x; | |
x0 = x.**0; | |
zeroth_moment(i) = dot(m,x0); | |
first_moment(i) = dot(m,x); | |
second_moment(i) = dot(m,x2); | |
endfor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
da |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N_PARTICLE = 4 | |
N_SIMULATIONS = 10000 | |
N_DIM = 2 | |
POS_RANGE = 2 | |
MASS_RANGE = 100 | |
zeroth_moment = zeros(N_SIMULATIONS,1); | |
first_moment = zeros(N_SIMULATIONS,N_DIM); | |
second_moment = zeros(N_DIM,N_DIM,N_SIMULATIONS); | |
Ixx = zeros(N_SIMULATIONS,1); | |
Iyy = zeros(N_SIMULATIONS,1); | |
Ixy = zeros(N_SIMULATIONS,1); | |
for i = 1:N_SIMULATIONS | |
m = MASS_RANGE*rand(N_PARTICLE,1); | |
x = (2*rand(N_PARTICLE,N_DIM)-1)*POS_RANGE; %between -POS_RANGE and POS_RANGE to have both | |
second_moment_particle = zeros(N_PARTICLE,N_DIM,N_DIM); | |
zeroth_moment(i) = sum(m); | |
first_moment(i,:) = transpose(transpose(x)*m); | |
for part = 1:N_PARTICLE | |
second_moment(:,:,i) = second_moment(:,:,i) + m(part).*transpose(x(part,:))*x(part,:); | |
endfor | |
endfor | |
for i = 1:N_SIMULATIONS | |
Ixx(i) = second_moment(1,1,i); | |
Iyy(i) = second_moment(2,2,i); | |
Ixy(i) = second_moment(1,2,i); | |
endfor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment