problemset3

The simulation results are time averaged from the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: el A of the nonlinear drift problem, compared to the theoretical curve. The simulation results are time-averaged from the 100th iteration to the 5100th iteration. density profile forming at the top of the standing wave. These tend to grow and then dissipate; an example is shown in figure 8. A C++ code for calculating the decaying random walk This code simulates 105 walkers from the decaying PDF. The code receives the value of a as the first input from the command line, and calculates the number of steps that must be computed in � order for the final step to be of size 10−5 . The code prints a list of X∞ points to the standard output. #include <cstdio> #include <iostream> #include <cmath> using namespace std; const int trials=100000; const float tol=0.00001; int main (int argc, char ∗ argv) { float a=atof(argv[1]),x,y,s;int i,j,k,r; k=int (log(tol)/log(a)+1); for(i=0;i<trials;i++) { x=y=0;s=a; for (j=0;j<k;j++) { r=rand()%4; if (r>1) x+=r==2?−s:s; else y+=r==0?−s:s; M. Z. Bazant – 18.366 Random Walks and Diffusion – Problem Set 3 Solutions 12 80 Simulation Theory 70 ρ 60 50 40 30 20 -4 -3 -2 -1 0 1 2 3 4 x Figure 7: Simulation output for model B of the nonlinear drift problem, compared to the theoretical curve. The simulation results are time-averaged from the 100th iteration to the 400th iteration. s ∗ =a; } cout << i << " " << x << " " << y << endl; } } B Simple C++ code for simulating model A #include <string> #include <iostream> #include <cstdio> #include <cmath> using namespace std; const const const const const const const const const int iter=5100; //Total number of iterations float dx=0.2; //Width for calculating local density float rhomax=100; //Value of rho max float lrho=25; //Value of rho for x<−4 float rrho=75; //Value of rho for x>4 float mx=4; //Half−width of simulation region float udt=0.01; //u max ∗ dt; float ddt=sqrt(0.01∗2/4); //sqrt(2∗D ∗...
View Full Document

Ask a homework question - tutors are online