1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
// Call the two functions
double XDiffusion (int D, int DII, int x, int s, double dt)
{
double Bx[2] = {cos(x),-sin(x)}; // define the magnetic field
return Bx[0]*sqrt(2*DII*dt)*s + Bx[1]*sqrt(2*D*dt)*s;
}
double YDiffusion (int D, int DII, int x, int s, double dt)
{
double By[2]= {sin(x), cos(x)}; // define the magnetic field
return By[0]*sqrt(2*DII*dt)*s + By[1]*sqrt(2*D*dt)*s;
}
int main()
{
int T =100;
int N = 1000;
double dt = double (T)/ N;
int x = 0;
int D = 10;
int DII = 10000;
// s is random number
srand(time(0));
float s = (float(rand())/(RAND_MAX)) + 1;// give random number between(0,1)
float resultX,resultY;
resultX = XDiffusion(D,DII,x,s,dt);
resultY = YDiffusion(D,DII,x,s,dt);
cout << "The result: " << resultX << " "<< resultY << endl;
return 0;
}
|