0

Hello,
I am trying to write two equations, each element in the equation is an arry ,

double XDiffusion (int D,int D11, int x, int s)
 {
    float DeltaX;
    return DeltaX;
 }

double YDiffusion (int D,int D11, int x, int s)
 {    
    float DeltaY;
    return DeltaY;
 }


int main()
{

int T =100;
int N = 1000;
float dt = float (T)/ N;
int x = 0; 
int D = 10;
int DII = 10000;

double Bx[2] = {cos(x),-sin(x)};
double By[2]= {sin(x), cos(x)};

srand(time(0));
float   s = (float(rand())/(RAND_MAX)) + 1;// give random number between(0,1)

  float  DeltaX = Bx[0]*sqrt(2*D*dt)*s + Bx[1]*sqrt(2*DII*dt)*s;  
  float  DeltaY = By[0]*sqrt(2*D*dt)*s + By[1]*sqrt(2*DII*dt)*s;

  cout << "the value is: " <<D <<'\n'<< endl ;
  cout << " The value is:" << DeltaY<< '\n'<< endl;
  return 0;
}

this is what I wrote so far:

2
Contributors
6
Replies
36
Views
1 Year
Discussion Span
Last Post by ALosh99
0

I don't know if I defined the equations correctly, I did not get any syntax error.
when I compile the code

1

Your code isn't complete the X and Y Diffusion functions do nothing, and you never call them from your base code. Think about what you are doing, and make sure that the code reflects that thinking, algorithmically speaking.

0

thank you for your reply ,you are completly right, I do not know what I have to do to make it work and useful

1

So describe precisely what the equations are supposed to do - pseudo code helps - and make some effort to code the algorithms. Also, did you mean to output the value of an unmodified variable D, or did you mean to output the value of DeltaX in main()? In addition, the '\n' is not needed as endl will output a newline for you, as well as flushing the stream.

0

The question is how the particles diffuse in magnetic field in two dimension. using these two equation(DeltaX,DeltaY).

I defined the magnetic filed as an array:
// define the magnetic filed:

double Bx[2] = {cos(x),-sin(x)}; // x is any angle
double By[2]= {sin(x), cos(x)};

I defined the random number also as an array.
then I multiply(insert) these two array (of the magnetic filed ,and the random number) in the two equation above.
After defined the two equation correctly ,I will plot it.

0

This is what I wrote so far in my code:

// 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;
}

Edited by ALosh99

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.