problemset3

# 5rand max void blocks forint i0ibli cout

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i=0; while(i<a) { if (abs(w[i]+=v[i])>mx) { v[i]=v[a]; w[i]=w[−−a]; } else i++; } j=poisson(lrate); for(i=0;i<j;i++) w[a++]=lspeed ∗ rnd()−mx; } for(i=0;i<blocks;i++) { r=(float(i)+0.5)/isp−mx; cout << r << " " << float(as[i])∗blocks/2/mx/(iter−100) << endl; } } D Advanced C++ code for simulating the nonlinear drift model #include <string> #include <iostream> #include <cstdio> #include <cmath> using namespace std; const const const const const const const const const const int iter=20000; int bl=3200; float dx=0.1; float rhomax=40000; float lrho=10000; float rrho=30000; float mx=4; float udt=0.01; float ddt=0.05; int smooth=40; //Total number of iterations //Number of memory blocks //Width for calculating local density //Value of rho max //Value of rho for x<−4 //Value of rho for x>4 //Half−width of simulation region //u max ∗ dt; //D ∗ dt; //Smoothing factor const const const const const const const const const float pi=3.1415926535897932384626433832795; int lwalk=int(mx ∗ lrho); //Total initial walkers on LHS int twalk=int(mx ∗ (lrho+rrho)); //Total initial walkers float ibs=bl/mx/2; //Inverse block spacing float lspeed=udt∗(1−lrho/rhomax)+ddt; float rspeed=ddt−udt∗(1−rrho/rhomax); float lrate=0.5∗lspeed ∗ lrho; //L. walker intro rate float rrate=0.5∗rspeed ∗ rrho; //R. walker intro rate int res=bl/smooth; //Number of data points to save M. Z. Bazant – 18.366 Random Walks and Diﬀusion – Problem...
View Full Document

## This note was uploaded on 01/23/2014 for the course MATH 18.366 taught by Professor Martinbazant during the Fall '06 term at MIT.

Ask a homework question - tutors are online