CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 21

Threaded View

  1. #10
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Re: Complex numbers and equation optimization using GA

    Craig,

    I just finished going through your second round code.

    We are coming along pretty well. But this will take a few more rounds.

    We need to:
    1) Fully understand the use of complex
    2) Get the numerics correct
    3) Get the right architecture

    Let's concentrate on numbers one and two for now.

    I have reworked your code and it does compile now using Visual C 9 as well as g++ 4.3.0.

    To answer your question about the imaginary number i, you can simply define i to be (0.0, 1.0). I have done this in the reworked code and actually created a subroutine called I(...) which returns a constant reference to this imaginary number. Again, the name 'I()' is taken from the Mathematica naming convention. So this number can simply be used anywhere any complex can be used.

    You had significant troubles because you were trying to set doubles equal to the values of complex'es. You must find the right place in the algorithms to switch over to real values by extracting the real and imag parts using the member functions real(...) and imag(...). In my re-worked code, the calculations are carried out to the end using complex'es.

    Where do you want to switch to real values?

    I am concerned with the complexity of the expressions for F1, F2 and F3. The lines which set F1, F2 and F3 are overly complicated. These lines should be simplified, you know broken down into multiple lines featuring their their constituent parts using additional helper variables, combining them later into F1, F2 and F3.

    In general your code could be improved by making more use of parentheses and groupings. You make heavy reliance on operator precedence. This was especially evident for AA, BB, etc. I did a bit of grouping but, in doing so, probably actually broke the code.

    You must go through all of the mathematics and we need to make sure that we are actually getting the right numbers.

    Usually I start small, check each algorithm line, and progress to the final answer. We are a bit backwards here because a body of unchecked mathematical code exists and we are refactoring it. We still need to establish the numerical integrity top-down up to the end.

    So I want you to do the following:

    1) Take my re-worked code.
    2) Simplify the things that I suggested and establish better use of groupings and parentheses.
    3) Identify the right place to extract the real and imag parts.
    4) Try to verify the numerical integrity of some intermediate results such as F1, F2, F3.

    We will go a few rounds after that. I will be out and about a lot because it is the weekend. Perhaps I might not respond until Sunday. But I will respond.

    Good luck with the next steps.

    Sincerely, Chris.
    Attached Files Attached Files
    You're gonna go blind staring into that box all day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured