tailieunhanh - Computational Physics - M. Jensen Episode 2 Part 1

Tham khảo tài liệu 'computational physics - m. jensen episode 2 part 1', kỹ thuật - công nghệ, cơ khí - chế tạo máy phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | . DIFFUSION EQUATION AND RANDOM WALKS 169 include iomanip include using namespace std Function to read in data from screen note call by reference void initialise int int double The Mc sampling for random walks void mc_sampling int int double int int prin ts to screen the results of the calculations void output int int int int int main int max_trials number_walks double move_probability Read in data i n i t i a l i s e max_trials number_walks move_probability int walk_cumulative new int number_walks 1 int walk2_cumulative new int number_walks 1 for int walks 1 walks number_walks walks walk_cumulative walks walk2_cumulative walks 0 end in i ti aliza tion of vectors Do th e mc sampling mc_sampling max_trials number_walks move_probability walk_cumulative walk2_cumulative Prin t out results output max_trials number_walks walk_cumulative walk2_cumulative d elete w alk_cumul ative fre e memory delete walk2_cumulative return 0 end main fun c ti on The input and output functions are void initialise int max_trials int number_walks double move_probability cout Number of Monte Carlo trials cin. . cout Number of attempted walks cin number_walks cout Move probability cin move_probability end of function initialise 170 CHAPTER 10. RANDOM WALKS AND THE METROPOLIS ALGORITHM void output int max_trials int number_walks int walk_cumulative int walk2_cumulative . . ofstream ofile testwalkers . dat for int i 1 i number_walks i double xaverage walk_cumulative i double max_trials double x2average walk2_cumulative i double m ax_tri al s double variance x2average xaverage xaverage ofile setiosflags ios showpoint ios uppercase ofile setw 6 i ofile setw 15 setprecision 8 xaverage ofile setw 15 setprecision 8 variance endl ofile . close end of function output The algorithm is in the function mc_sampling and tests the probability of moving to the left or to the right by generating a random number. void mc_sampling int max_trials int number_walks double move_probability .

TỪ KHÓA LIÊN QUAN