# Thread: How do I solve this logarithmic equation?

1. ## How do I solve this logarithmic equation?

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..

2. 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.

3. you could use newton method to find zeroes to an equation like :

log y +A +B y = 0

http://en.wikipedia.org/wiki/Newton's_method
EDIT: read also the "counter example" section to see when this method does not work.

4. I do not really see a reason why when asked a help to implement one specific method of solving the equation everyone starts to give advices how to use other methods for this purpose?

I think the OP should slightly change the equation to bring it to form

y = f(x);

when write a function
double f(double x)

that calculates the above
and then write a loop
Code:
```do
{
x = y ;
y = f(x);
}while(abs(y-x) > delta);```
properly initializing y and delta before loop.

5. Originally Posted by vart
I do not really see a reason why when asked a help to implement one specific method of solving the equation everyone starts to give advices how to use other methods for this purpose?
because that method will never solve the equation.

6. Originally Posted by vart
I do not really see a reason why when asked a help to implement one specific method of solving the equation everyone starts to give advices how to use other methods for this purpose?

I think the OP should slightly change the equation to bring it to form

y = f(x);

when write a function
double f(double x)

that calculates the above
and then write a loop
Code:
```do
{
x = y ;
y = f(x);
}while(abs(y-x) > delta);```
properly initializing y and delta before loop.
What good would properly initializing y do, when your first command in the do loop, is to reset it's value to the value of x?

To converge on an answer, your logic should show something that converges. Perhaps that was implied, but it is not explicitly shown.

Can you elaborate on that, Vart, keeping in mind that I wouldn't know "proper form" from a Cocker Spaniel, here?

7. Originally Posted by alreadyinuse
because that method will never solve the equation.
http://en.wikipedia.org/wiki/Iterative_method

You should go back to school

8. Originally Posted by Adak
What good would properly initializing y do, when your first command in the do loop, is to reset it's value to the value of x?
Maybe it is because I set the value of x to be equal to y?

Originally Posted by Adak
Can you elaborate on that, Vart, keeping in mind that I wouldn't know "proper form" from a Cocker Spaniel, here?
Elaborate what?

9. Originally Posted by vart
Maybe it is because I set the value of x to be equal to y?

Elaborate what?
Well the x, y thing is solved with a few less cobwebs from the Sandman, and perhaps a bit of caffeine.

Unfortunately, the link has nothing really useful unless you're into calculus.

10. Originally Posted by vart
I know what an iterative method is, otherwise I would have not suggest newton method.

The problem is that to use your method you have to be sure that the solution is an attractive fixed point. example:

y=f(x)= -3 + 5x
if I want to solve y=f(y) I cannot use your method:
x=0 y= -3
x=-3 y=-18
and so on.

Now, unicorn is trying to solve:
log y=-4.4132+0.0302x
that on a Real field should be equal to:
y=f(x)=exp(-4.4132+0.0302x)
with y=f(y).
If I solved it well there are 3 fixed points, but only 2 are stable/attractive:
a=0.0121 b=339 c=infinity

with your method you can find "a" and (in theory) "c" but you cannot find "b" because "b" is an unstable fixed point.

Generally speaking that method is really weak as you cannot see at a glance all the properties of the function.

And yes, I will go back to school....

11. Originally Posted by alreadyinuse
with your method you can find "a" and (in theory) "c" but you cannot find "b" because "b" is an unstable fixed point.
So what's your point? It is not my method - it is method OP needs to implement. Even if it has some limitations.

Popular pages Recent additions