# Forum: discussion

Monitor Forum | Start New Thread
| |

RE: Multiplicative inverse calculation [ Reply ] By: Jens Gustedt on 2020-08-03 07:08 | [forum:153532] |

Hello, > On page 24 there is an example of iterating to calculate the multiplicative inverse of a > number. When I run this code however, it overshoots the answer and goes into an > infinite loop towards -inf. oh but I guess it should merely be alternating in sign for a while and not always be negative > Is this intentional? no, not at all take it as a perfect example why we should always try out examples before we put them in papers or books :) The problem here is that the initial value for x is not good enough. If it were closer to 1/34, the procedure should converge. My error was to assume that this method (Heron's) would converge from everywhere. It does that, I think, when used for computing the nth root, where n > 1, but when n = -1, the initial value has to be already relatively close. Sorry for that Jens |

Multiplicative inverse calculation [ Reply ] By: Nobody on 2020-06-19 14:13 | [forum:153529] |

On page 24 there is an example of iterating to calculate the multiplicative inverse of a number. When I run this code however, it overshoots the answer and goes into an infinite loop towards -inf. Is this intentional? ` # include < tgmath .h > double const eps = 1 E - 9; ... double const a = 34.0; double x = 0.5; while ( fabs (1.0 - a * x ) >= eps ) { x *= (2.0 - a * x ) ; } ` |