CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Search:

Type: Posts; User: 2kaud

Search: Search took 0.07 seconds.

  1. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    No

    If delta_E <= 0 then flip
    if delta_E > 0 then flip if exp(-delta_E) > random_number_0_to_1

    When evaluating logical or conditions, the left hand expression is evaluated first. If this is...
  2. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    if (delta_E <= 0 || ((double)rand() / (double)(RAND_MAX)) < (double)exp((double)-delta_E))

    the if condition is a logical or. If either or both of the seperate conditons (left and right of the ||)...
  3. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    To store data in a file, you first need to open the file for writing and then output data to the file. Data can be written to the file using stream insertion (just like << for cout).
    See...
  4. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Well as long as it seems then that's all right then? Have you tested it to make sure it gives the answers expected? I don't think it will as x and y are only set once at the beginning of the program...
  5. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Fine. So just do the quick change to the code so that it matches what you want to do and then you'll have it.
  6. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Not really. If you want x and y to selected differently for each loop then the for needs to be before the int x. Do you want neighbour etc to be reset each time around the loop or values covering all...
  7. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    What is the variable T? || in c++ conditional expression means logical OR. ie if either or both of the conditions are met then the condition is evaluated to TRUE. drand48() returns a random number in...
  8. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Yes, as in maths the x-axis should go left to right and the y-axis go top to bottom.



    ?? :confused:



    This comes back to what is meant by a sweep? During one sweep can the same element be...
  9. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Upon looking at the code I put together from your previous postings, there appears to be inconsitencies between which element of the matix is considered to be x and which to be y. I think the code...
  10. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    If you are using Windows 7 why don't you use the free Microsoft Visual Studio Express 2013?
    See http://www.visualstudio.com/downloads/download-visual-studio-vs
    You want Visual Studio Express 2013...
  11. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    spin(x, y) *= -1; // flip spin

    As the class is currently coded, you can't do this as operator() returns a value not a reference. You need to change operator() to


    int& operator()(int x,...
  12. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    If you haven't met c++ classes before, you need a crash course in them.
    See
    http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/
    http://www.cplusplus.com/doc/tutorial/classes/...
  13. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    No. There is no implied boundary conditions in your code. That is why you are getting absurd values. The boundary conditions need to be part of spin() - so spin() needs to be function instead of just...
  14. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    if(x<0) x += LatSize;
    if(x>=LatSize) x -= LatSize;
    if(y<0) y += LatSize;
    if(y>=LatSize) y -= LatSize;

    these statements are not needed as x and y will always satisfy the condition >= 0 and...
  15. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    int x = int (rand()*LatSize);
    int y = int (rand()*LatSize);


    What's with the '*' ? It should be % (modulo) as per my post #2!



    int x = int (rand()%LatSize);
    int y = int (rand()%LatSize);
  16. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    I agree - that's why I said in my post #10 that the easiest way would be to do text-replace. :) I only offered the #define as an option to try to get the code posted by the OP to compile as I...
  17. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Like this


    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    using namespace std;

    #define spin(a, b) (matrix[(a)][(b)])
  18. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Possibly the easiest way is to replace spin(...) by matrix[...].

    Another way would be to use a define at the top of the code


    #define spin(x,y) (matrix[(x)][(y)])
  19. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    As I explained in my previous post #2. What is the function spin? This is being used but isn't defined.
  20. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    Please use code tags when you post code as you did in post #1.

    As ROWS and COLS are now not defined, you could use


    const int LatSize = 5;
    int matrix[LatSize][LatSize];

    ...
  21. Replies
    47
    Views
    56,483

    Re: Ising Model C++ Metropolis Algorithm

    I'm not sure I fully understand what you are trying to accomplish. However, looking at the code I can offer some observations which may be of help.

    With reference to your NxN lattice. As the...
Results 1 to 21 of 21





Click Here to Expand Forum to Full Width

Featured