Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Finding a value by approximation / estimation

Thread view: 
UKP - 25 Sep 2007 14:14 GMT
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
Gordon Beaton - 25 Sep 2007 14:18 GMT
> 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

--
UKP - 25 Sep 2007 14:35 GMT
> 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.
Gordon Beaton - 25 Sep 2007 15:00 GMT
> I'm trying to find out some Root Finding examples in Java, although
> no luck yet.

Search terms like "newton raphson", "runge kutta" or "numerical
methods" together with Java result in many relevant hits.

This might also help:
http://math.nist.gov/javanumerics/#libraries

/gordon

--
Andrew Thompson - 25 Sep 2007 14:20 GMT
>Say the values of a & b are given ...

<tongue in cheek>
"the values of a & b are given"
</tongue in cheek>

And as an aside.
1) Did you have a question, or were you simply
making a comment?
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?

Signature

Andrew Thompson
http://www.athompson.info/andrew/

UKP - 25 Sep 2007 14:39 GMT
> 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.
UKP - 25 Sep 2007 14:42 GMT
FYI: Any input I get here will be referred appropriately in my
program.
Joshua Cranmer - 25 Sep 2007 22:30 GMT
>> 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.

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.

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Roedy Green - 25 Sep 2007 23:11 GMT
>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/048641454X?ie=UTF8&tag=canadianmindprod&linkCod
e=as2&camp=1789&creative=9325&creativeASIN=048641454X

http://www.powells.com/partner/28995/biblio/9780486414546
http://search.barnesandnoble.com/booksearch/isbninquiry.asp?isbn=9780486414546&l
kid=J12871747&pubid=K49036

http://www.amazon.co.uk/gp/product/048641454X?ie=UTF8&tag=canadianmindp-21&linkC
ode=as2&camp=1634&creative=6738&creativeASIN=048641454X

http://www.amazon.ca/gp/product/048641454X?ie=UTF8&tag=canadianmin07-20&linkCode
=as2&camp=15121&creative=330641&creativeASIN=048641454X

http://www.jdoqocy.com/click-2358048-10437934?url=http%3A%2F%2Fwww.chapters.indi
go.ca%2Fbooks%2Fitem%2Fbooks-9780486414546%2F

http://www.amazon.fr/gp/product/048641454X?ie=UTF8&tag=canamindprod-21&linkCode=
as2&camp=1624&creative=6746&creativeASIN=048641454X

http://www.amazon.de/gp/product/048641454X?ie=UTF8&tag=canadianmin0b-21&linkCode
=as2&camp=1638&creative=6742&creativeASIN=048641454X

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 25 Sep 2007 23:12 GMT
>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 http://mindprod.com/jgloss/binarysearch.html
for a simpler, slower method than Newton Raphson.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Michael G Soyka - 26 Sep 2007 02:58 GMT
> 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/
[quoted text clipped - 14 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.