Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Back Room
  4. my math problem

my math problem

Scheduled Pinned Locked Moved The Back Room
questionalgorithmshelp
24 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Marshall

    lucy wrote: so how can I reverse this algorithm? That is, based on CompensatedX and CompensatedZ, how can I get the original XCentroid and ZCentroid? I just started looking this over and I'm affraid I have no answers yet, but do have a few questions. It looks like you are saying all that is known when you "reverse" this, is the values of CompensatedX and CompensatedZ. Is that right? I'd have a much better chance of helping you if I knew what you are trying to accomplish with this algorithm. In the context of your application, what does "compensate" mean? How did you arrive at the algorithm in it's current form? :)

    L Offline
    L Offline
    lucy 0
    wrote on last edited by
    #21

    Hi Marshall, As you can see from the first post, I get the CompensatedX and CompensatedZ from XCentroid and ZCentroid following the equations in the yellow box in my first post. In a math equation, it is: CompensatedX = XCentroid + FRACTION * Dr * XCentroid / VectLength; ---- Compensatedz = zCentroid + FRACTION * Dr * ZCentroid / VectLength; ---- where FRACTION is a constant of 0.009835, VectLength = sqrt(pow(XCentroid, 2), pow(ZCentroid, 2)); Dr = pow(Vect, 2.4); All the above is done in program 1. In my program 2, all I get is CompensatedX and CompensatedZ, and I need to reverse the above formula to get XCentroid and ZCentroid. But I couldn't get it. :-( I was told that I can use Newton-Rapson to approach it, but I don't know how. :-( Any more info do you need? I'd be glad to provide.

    M 1 Reply Last reply
    0
    • L lucy 0

      Hi Marshall, As you can see from the first post, I get the CompensatedX and CompensatedZ from XCentroid and ZCentroid following the equations in the yellow box in my first post. In a math equation, it is: CompensatedX = XCentroid + FRACTION * Dr * XCentroid / VectLength; ---- Compensatedz = zCentroid + FRACTION * Dr * ZCentroid / VectLength; ---- where FRACTION is a constant of 0.009835, VectLength = sqrt(pow(XCentroid, 2), pow(ZCentroid, 2)); Dr = pow(Vect, 2.4); All the above is done in program 1. In my program 2, all I get is CompensatedX and CompensatedZ, and I need to reverse the above formula to get XCentroid and ZCentroid. But I couldn't get it. :-( I was told that I can use Newton-Rapson to approach it, but I don't know how. :-( Any more info do you need? I'd be glad to provide.

      M Offline
      M Offline
      Marshall
      wrote on last edited by
      #22

      lucy wrote: I was told that I can use Newton-Rapson to approach it, but I don't know how. Newton's method? Yes, I suppose you could do that. You could certainly use it to find the roots - but since CompensatedZ is not a derivative of CompensatedX I don't see a quick application of Newton's method. I guess you could then solve as a system of equations, but it's too late for me to think straight on that. X| By the way, Newton's method (AKA Newton-Raphson) is an iterative method for estimating the roots (intercepts) of a function. You use it to find a value for x such that f(x) = 0. The trick is to make a good guess of x for the first iteration, else you'll end up going through a LOT more iterations than you want. So, if guess #1 is x1, then here's how it would work: x2 = x1 - [f(x1)/f '(x1)] x3 = x2 - [f(x2)/f '(x2)] . . . until xn is sufficiently close for your needs. I know that's probably not much help, :( but at least maybe you'll remember encountering Newton's method in a calculus course somewhere. I won't have time to play with this until lunch tomorrow so if you solve this before then, please let me know via email or posting on CP. Then I'll know if I can eat or do more math!:-D

      L 2 Replies Last reply
      0
      • M Marshall

        lucy wrote: I was told that I can use Newton-Rapson to approach it, but I don't know how. Newton's method? Yes, I suppose you could do that. You could certainly use it to find the roots - but since CompensatedZ is not a derivative of CompensatedX I don't see a quick application of Newton's method. I guess you could then solve as a system of equations, but it's too late for me to think straight on that. X| By the way, Newton's method (AKA Newton-Raphson) is an iterative method for estimating the roots (intercepts) of a function. You use it to find a value for x such that f(x) = 0. The trick is to make a good guess of x for the first iteration, else you'll end up going through a LOT more iterations than you want. So, if guess #1 is x1, then here's how it would work: x2 = x1 - [f(x1)/f '(x1)] x3 = x2 - [f(x2)/f '(x2)] . . . until xn is sufficiently close for your needs. I know that's probably not much help, :( but at least maybe you'll remember encountering Newton's method in a calculus course somewhere. I won't have time to play with this until lunch tomorrow so if you solve this before then, please let me know via email or posting on CP. Then I'll know if I can eat or do more math!:-D

        L Offline
        L Offline
        lucy 0
        wrote on last edited by
        #23

        Hi Marshall, Thank you for the reminder of Newton's method. I am approaching it. Will tell you once I got it proved. Have a nice lunch!

        1 Reply Last reply
        0
        • M Marshall

          lucy wrote: I was told that I can use Newton-Rapson to approach it, but I don't know how. Newton's method? Yes, I suppose you could do that. You could certainly use it to find the roots - but since CompensatedZ is not a derivative of CompensatedX I don't see a quick application of Newton's method. I guess you could then solve as a system of equations, but it's too late for me to think straight on that. X| By the way, Newton's method (AKA Newton-Raphson) is an iterative method for estimating the roots (intercepts) of a function. You use it to find a value for x such that f(x) = 0. The trick is to make a good guess of x for the first iteration, else you'll end up going through a LOT more iterations than you want. So, if guess #1 is x1, then here's how it would work: x2 = x1 - [f(x1)/f '(x1)] x3 = x2 - [f(x2)/f '(x2)] . . . until xn is sufficiently close for your needs. I know that's probably not much help, :( but at least maybe you'll remember encountering Newton's method in a calculus course somewhere. I won't have time to play with this until lunch tomorrow so if you solve this before then, please let me know via email or posting on CP. Then I'll know if I can eat or do more math!:-D

          L Offline
          L Offline
          lucy 0
          wrote on last edited by
          #24

          Hi Marshall, Here's the final resolution::laugh:

          void DeCompensate_For_Lens_Aberations(double *XCentroid, double *ZCentroid,
          double CompensatedX, double CompensatedZ)
          {
          double CompensatedVect = 0.0;
          double FRACTION = 0.009835;
          double EXPONENT = 2.4;

          double delta = 0.000000001;
          
          CompensatedVect = pow((sqrt((pow(CompensatedX, 2.0) + pow(CompensatedZ, 2.0))
                                       / pow(CompensatedX, 2.0))), (EXPONENT - 1.0));
          double inc = CompensatedX / 100;
          double rem = CompensatedX;
          if ( rem < 0 ) rem = -rem;
          int count = 0;
          double try\_value = CompensatedX - inc;
          while ( rem > delta )
          {
              // x2 = x1 - f(x)/f'(x);
              try\_value = try\_value -
                  (FRACTION \* pow(try\_value, EXPONENT) \* CompensatedVect + try\_value - CompensatedX)/       // f(x)
                  (FRACTION \* EXPONENT \* pow(try\_value, (EXPONENT - 1)) \* CompensatedVect + 1);            // f'(x)
          
              rem = FRACTION \* pow(try\_value, EXPONENT) \* CompensatedVect + try\_value - CompensatedX;
          
              if ( rem < 0 )
                  rem = -rem;
          
              count ++;
              if ( count > 30 )
                  break;
          } // end of Newton formula for X
          
          if ( count <= 30 )
          {
              \*XCentroid = try\_value;
              \*ZCentroid = \*XCentroid \* CompensatedZ / CompensatedX;
          }
          else
              \*ZCentroid = OUT\_OF\_RANGE;
          

          } /* end of DeCompensate_For_Lens_Aberations */

          The heart of this solution is the Newton algorithm. Thank you so much! The limitation is: the input CompensatedX and CompensatedZ cannot be negative since we need a pow(x, 2.4), which doesn't work for negative value. To overcome this, just put fabs(CompensatedX) and fabs(CompensatedZ) to the function, and after return from this function, do this:

          if ( CompensatedX < 0.0 )
          XCentroid = -XCentroid;
          if ( CompensatedZ < 0.0 )
          ZCentroid = -ZCentroid;

          Last but not least, thank all you guys who helped me in this problem. I appreciated it a lot.:rose: :rose: :rose: :rose: :rose:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups