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:

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

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.

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

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.

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.

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.