Originally Posted by

**unicorn**
Hello everyone, my homework is writing a prog. solving

"log y=-4.4132+0.0302x" (y is equal to x) equation by iteration. What program will do is beginning with x=0 then finding a y value. After putting this y value in place of x in the equation, again finding a new y value and this continues until we find y=x.

y is approx. 3.86*10 to the power (-5).

I am not good at C. I dont expect you to do the entire hw. but if you help me showing a solution way I will be glad.Thanks..

That's alright, I'm so rusty with math, I think a log is something for the fireplace.

A very simple and straight forward approach would be something like: (in rough code)

Code:

double step = *VERY* tiny incremental amount or step.
double y = incredibly small value. It MUST be less than y + step's real value.
do {
y += step;
log y = -4.4132+0.0302y
}while (log y != -4.4132+0.0302y);

All the above is good, but it may not ever resolve on y's value. Especially if the step value is not oh-so-tiny.

A more elaborate idea would be to have two loops, in separate functions. StepUp, would be the above loop, StepDown would be just like that do loop, EXCEPT the stop condition would be like:

Code:

}while (log y <= -4.4132+0.0302y);
and for StepDown:
y = incredibly large value. MUST be greater than y - step's real value.
y -= step; /* <--note the minus just before the = sign here */
}while (log y >= -4.4132+0.0302y);

Now you call these functions, and then give you an approximation for y, but not exact. Now you call those same functions back, but with much tighter granularity for step, for both functions.

Repeat calls to these functions, alternating back and forth, until y is resolved. Step would be come smaller and smaller after every run through of the two functions, and y's starting value would be raised by StepUp, and lowered by StepDown, each time through them, as well.