Finding a value by approximation / estimation

U

UKP

Say the values of a & b are given (Note: a,b,c form an equation) Now,
would it be possible to find the value of c if a/b = (1 - (Math.pow(1/
(1 + c), 10*12)))/c;

See below (half-baked example) :
-----

while (check1!=check2){

check1 = a/b
check2 = (1 - (Math.pow(1/(1 + c), 10*12)))/c;

c= c + 1;

}

The moment check1=check2,
print c
 
G

Gordon Beaton

Say the values of a & b are given (Note: a,b,c form an equation) Now,
would it be possible to find the value of c if a/b = (1 - (Math.pow(1/
(1 + c), 10*12)))/c;

What happened when you tried?

BTW if c is an int, the expression 1/(1+c) is zero for most values
of c.

/gordon


--
 
A

Andrew Thompson

U

UKP

What happened when you tried?

- I'm not even sure if the above guessed "algorithm" will work in
Java.
I'm trying to find out some Root Finding examples in Java, although no
luck yet.
 
U

UKP

2) If you did have a question, would it not be
better to put that question (if any) to a group
related to computational algorithms?

I'm kind of unsure whether to go for root finding or approximation to
solve this.
 
J

Joshua Cranmer

UKP said:
I'm kind of unsure whether to go for root finding or approximation to
solve this.
Well, right now we're covering equation solving in my numerical analysis
class, so I'll do my best to answer.

Solving f(x) = y is trivially transformed into g(x) = 0 by setting
g(x)=f(x)-y, so I will assume without loss of generality that you are
trying to find f(x) = 0.

The simplest method is the bisection method. If you know an a and b such
that sgn(f(a)) = -sgn(f(b)) and a<x<b, then you can apply the following
iterative process continuously:

c = (a+b)/2
if f(c)*f(a) > 0; then
a = c
else
b = c
fi
if (a-b)/2 < epsilon then quit

The bisection method, however, cannot find roots such that are local
optima (comparing the derivative will then work in that case).

Given that you know f(x), you can iteratively apply a fixed-point
iteration scheme using Newton's method. Fixed-point iteration transforms
f(x) = 0 to an equation g(x) = x; Newton's method is an analytic way to
find g(x) that makes g'(0) = 0 (and thus converges really quickly if it
actually converges. Convergence not guaranteed).

Newton's method finds g(x) = x - f(x)/f'(x), and then you can
iteratively apply x_{i+1} = g(x_i) until x_i/x_{i+1} < epsilon.

If you need better accuracy or convergence (depends on the problem),
then http://en.wikipedia.org/wiki/Root-finding_algorithm will be
sufficient to help you (Brent's Method is the most commonly used but
probably the most difficult to write).

P.S. In case you couldn't tell, yes, the root-finding algorithm is the
way to go here.
 
R

Roedy Green

Say the values of a & b are given (Note: a,b,c form an equation) Now,
would it be possible to find the value of c if a/b = (1 - (Math.pow(1/
(1 + c), 10*12)))/c;

I took a year course on this at university which I loved since in
combined math and computer science. Anthony Ralston wrote the
textbook. Google "Newton Raphson" for the basic technique. Basically
you use the slope of your equation to predict the next guess as you
home in. There are dozens of techniques for numerically solving
differential equations. I recall my delight at the accuracy of one of
my punch card FORTRAN programs that used a variable step size with
first and second order next guess approximations.


A First Course in Numerical Analysis
ISBN10: 0-486-41454-X
ISBN13: 978-0-486-41454-6
Anthony Ralston, Philip Rabinowitz

http://www.amazon.com/gp/product/04...mp=1789&creative=9325&creativeASIN=048641454X
http://www.powells.com/partner/28995/biblio/9780486414546
http://search.barnesandnoble.com/bo...sbn=9780486414546&lkid=J12871747&pubid=K49036
http://www.amazon.co.uk/gp/product/...mp=1634&creative=6738&creativeASIN=048641454X
http://www.amazon.ca/gp/product/048...15121&creative=330641&creativeASIN=048641454X
http://www.jdoqocy.com/click-235804...ers.indigo.ca/books/item/books-9780486414546/
http://www.amazon.fr/gp/product/048...mp=1624&creative=6746&creativeASIN=048641454X
http://www.amazon.de/gp/product/048...mp=1638&creative=6742&creativeASIN=048641454X
 
M

Michael G Soyka

UKP said:
Say the values of a & b are given (Note: a,b,c form an equation) Now,
would it be possible to find the value of c if a/b = (1 - (Math.pow(1/
(1 + c), 10*12)))/c;

See below (half-baked example) :
-----

while (check1!=check2){

check1 = a/b
check2 = (1 - (Math.pow(1/(1 + c), 10*12)))/c;

c= c + 1;

}

The moment check1=check2,
print c
Before you choose a numerical method, you need to understand your
problem. For example, if a Java application requires a container, you
wouldn't just throw a dart and pick the one you hit.

Besides, bisection and Newton-Raphson all require initial guesses.
Where will you get them?

I suggest you start by doing some simple analysis using paper and
pencil. If you do this, you will find that (a) there are one, two, or
three possible solutions depending on the value of a/b, and (b) you will
get a idea of where the solutions lie. You will also find that c=0 is a
solution iff a/b=1.

Hint: multiply both sides of your equation by "c", then start thinking!


Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top