my math problem
-
Hey man! I'm just joking with ya! I don't know what your doing at all! So I just tried to make you confused... and it worked! :laugh: :-D ;P ------------------------------------ ****Rickard Andersson, Suza Computing ICQ#: 50302279 I'm from the winter country SWEDEN! ------------------------------------
-
Hi Lucy, I'm humbled that you selected me. :-) The best answer I have seen for your problem was by Chris M in the lounge where he made an assumption about Y. However I couldn't understand how he arrived at it. :-( But the code you have posted looks better than your Math, so I'll have a try soon and see if I can sove it. I'm unsure how the condition
if ( VectLength != (double)0.0 )
will relate to the solution Regardz Colin J Davies
Sonork ID 100.9197:Colin
More about me :-)
-
Hi Lucy, I'm humbled that you selected me. :-) The best answer I have seen for your problem was by Chris M in the lounge where he made an assumption about Y. However I couldn't understand how he arrived at it. :-( But the code you have posted looks better than your Math, so I'll have a try soon and see if I can sove it. I'm unsure how the condition
if ( VectLength != (double)0.0 )
will relate to the solution Regardz Colin J Davies
Sonork ID 100.9197:Colin
More about me :-)
****Colin Davies wrote: Hi Lucy, I'm humbled that you selected me. Blast! She posted that in the Lounge and I re-directed her to the sopabox and told her that Colin davies can help her :-) She first mis-posted it in the C++ forum. Then she came to the right forum. You can thank me too :-) Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
-
Rickard Andersson wrote: YOU are in the wrong forum, dude! what's the correct forum? I posted it in lounge, and I was told I was doing it wrongly. Nish suggested I could try here, and I got the same response. :(( also, why Rickard Andersson wrote: lucy wrote: Dr = FRACTION * ( pow(VectLength, EXPONENT) ); Thats wrong! this is wrong? I am using a math function from C++, and I think the syntax is correct? :confused: :confused:
lucy wrote: what's the correct forum? Colin has been posting a lot of math related stuff in this forum ever since it got renamed to soapbox. That's why I asked you to post it here. By the way I saw that you also posted it in the VC++ forum. Was that before or after the sopabbox post? And did anuyone answer youi there? Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
-
****Colin Davies wrote: Hi Lucy, I'm humbled that you selected me. Blast! She posted that in the Lounge and I re-directed her to the sopabox and told her that Colin davies can help her :-) She first mis-posted it in the C++ forum. Then she came to the right forum. You can thank me too :-) Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
Nish [BusterBoy] wrote: She first mis-posted it in the C++ forum. Then she came to the right forum. Read down a bit; she was re-directed to the C++ forum after posting here. Poor post, looking for a home... :) --------_**
When will I realize that this skin I'm in Hey, it isn't mine And when will the kill be too much meat for me to hide on...
**_
-- Blind Melon, Skinned
-
Nish [BusterBoy] wrote: She first mis-posted it in the C++ forum. Then she came to the right forum. Read down a bit; she was re-directed to the C++ forum after posting here. Poor post, looking for a home... :) --------_**
When will I realize that this skin I'm in Hey, it isn't mine And when will the kill be too much meat for me to hide on...
**_
-- Blind Melon, Skinned
Shog9 wrote: Poor post, looking for a home... This is indeed a sad state of affairs if a post cannot find a forum of its own :( Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
-
Shog9 wrote: Poor post, looking for a home... This is indeed a sad state of affairs if a post cannot find a forum of its own :( Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
Then, where can I post my turbo C++ / ASM / BIOS question?? Here's that question: I am trying to write a DOS program to wake up the BIOS program on AGP card...... :confused: Maxwell Chen People say "No news is good news". Then, no code is good code!?
-
here is the original code
void Compensate(float XCentroid, float ZCentroid,
float *CompensatedX, float *CompensatedZ)
{
double Dr = 0.0;
double LCentroidX = 0.0;
double LCentroidZ = 0.0;
double VectLength = 0.0;
double FRACTION = 0.009835;
double EXPONENT = 2.400;LCentroidX = (double)XCentroid; LCentroidZ = (double)ZCentroid; VectLength = sqrt( (pow(LCentroidX, 2.0)) + (pow(LCentroidZ, 2.0)) ); Dr = FRACTION \* ( pow(VectLength, EXPONENT) ); if ( VectLength != (double)0.0 ) { \*CompensatedX = (float)LCentroidX + ( Dr \* ( LCentroidX / VectLength ) ); \*CompensatedZ = (float)LCentroidZ + ( Dr \* ( LCentroidZ / VectLength ) ); } else { /\* return original co-ordinates \*/ \*CompensatedX = XCentroid; \*CompensatedZ = ZCentroid; } return;
} /* end Compensate */
so how can I reverse this algorithm? That is, based on CompensatedX and CompensatedZ, how can I get the original XCentroid and ZCentroid? I tried the following, but it doesn't work.
CompensatedVect = sqrt(pow(CompensatedX, 2.0), pow(CompensatedZ, 2.0));
CompensatedDr = pow((CompensatedVect/FRACTION), 1/EXPONENT);
XCentroid = CompensatedX / (1 + ompensatedDr/CompensatedVect);
ZCentroid = CompensatedZ / (1 + CompensatedDr/CompensatedVect);I tried to solve it using a pen and piece of paper, I got the reverse formula. But when I translated the formula to C++ code, I got a wrong answer.... :(( :(( :(( Maxwell Chen People say "No news is good news". Then, no code is good code!?
-
lucy wrote: what's the correct forum? Colin has been posting a lot of math related stuff in this forum ever since it got renamed to soapbox. That's why I asked you to post it here. By the way I saw that you also posted it in the VC++ forum. Was that before or after the sopabbox post? And did anuyone answer youi there? Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
Nish [BusterBoy] wrote: And did anuyone answer youi there? Yeah, Felix Gartsman answered me in lounge. But I had no luck in C++ forum. Felix said I should use Newton-Rapson algorithm. I am trying to find out what the algorithm is. I haven't touched such kind of stuff for how many years? 8 or ten?:((
-
Hi Lucy, I'm humbled that you selected me. :-) The best answer I have seen for your problem was by Chris M in the lounge where he made an assumption about Y. However I couldn't understand how he arrived at it. :-( But the code you have posted looks better than your Math, so I'll have a try soon and see if I can sove it. I'm unsure how the condition
if ( VectLength != (double)0.0 )
will relate to the solution Regardz Colin J Davies
Sonork ID 100.9197:Colin
More about me :-)
-
here is the original code
void Compensate(float XCentroid, float ZCentroid,
float *CompensatedX, float *CompensatedZ)
{
double Dr = 0.0;
double LCentroidX = 0.0;
double LCentroidZ = 0.0;
double VectLength = 0.0;
double FRACTION = 0.009835;
double EXPONENT = 2.400;LCentroidX = (double)XCentroid; LCentroidZ = (double)ZCentroid; VectLength = sqrt( (pow(LCentroidX, 2.0)) + (pow(LCentroidZ, 2.0)) ); Dr = FRACTION \* ( pow(VectLength, EXPONENT) ); if ( VectLength != (double)0.0 ) { \*CompensatedX = (float)LCentroidX + ( Dr \* ( LCentroidX / VectLength ) ); \*CompensatedZ = (float)LCentroidZ + ( Dr \* ( LCentroidZ / VectLength ) ); } else { /\* return original co-ordinates \*/ \*CompensatedX = XCentroid; \*CompensatedZ = ZCentroid; } return;
} /* end Compensate */
so how can I reverse this algorithm? That is, based on CompensatedX and CompensatedZ, how can I get the original XCentroid and ZCentroid? I tried the following, but it doesn't work.
CompensatedVect = sqrt(pow(CompensatedX, 2.0), pow(CompensatedZ, 2.0));
CompensatedDr = pow((CompensatedVect/FRACTION), 1/EXPONENT);
XCentroid = CompensatedX / (1 + ompensatedDr/CompensatedVect);
ZCentroid = CompensatedZ / (1 + CompensatedDr/CompensatedVect);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? :)
-
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? :)
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.
-
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.
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
-
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
-
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
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: