Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.java.* > Newsgroup comp.lang.java.programmer

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 09-25-2007, 01:14 PM
UKP
Guest
 
Posts: n/a
Default Finding a value by approximation / estimation

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

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 09-25-2007, 01:18 PM
Gordon Beaton
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

On Tue, 25 Sep 2007 13:14:16 -0000, UKP wrote:
> 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


--
Reply With Quote
  #3 (permalink)  
Old 09-25-2007, 01:20 PM
Andrew Thompson
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

UKP wrote:
>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?

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200709/1

Reply With Quote
  #4 (permalink)  
Old 09-25-2007, 01:35 PM
UKP
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation


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


Reply With Quote
  #5 (permalink)  
Old 09-25-2007, 01:39 PM
UKP
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation


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

Reply With Quote
  #6 (permalink)  
Old 09-25-2007, 01:42 PM
UKP
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

FYI: Any input I get here will be referred appropriately in my
program.

Reply With Quote
  #7 (permalink)  
Old 09-25-2007, 02:00 PM
Gordon Beaton
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

On Tue, 25 Sep 2007 13:35:03 -0000, UKP wrote:
> 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

--
Reply With Quote
  #8 (permalink)  
Old 09-25-2007, 09:30 PM
Joshua Cranmer
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

UKP wrote:
>> 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.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Reply With Quote
  #9 (permalink)  
Old 09-25-2007, 10:11 PM
Roedy Green
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

On Tue, 25 Sep 2007 13:14:16 -0000, UKP <rockmode@gmail.com> wrote,
quoted or indirectly quoted someone who 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;


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/048...SIN=048641454X
http://www.powells.com/partner/28995.../9780486414546
http://search.barnesandnoble.com/boo...7&pubid=K49036
http://www.amazon.co.uk/gp/product/0...SIN=048641454X
http://www.amazon.ca/gp/product/0486...SIN=048641454X
http://www.jdoqocy.com/click-2358048...80486414546%2F
http://www.amazon.fr/gp/product/0486...SIN=048641454X
http://www.amazon.de/gp/product/0486...SIN=048641454X
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Reply With Quote
  #10 (permalink)  
Old 09-25-2007, 10:12 PM
Roedy Green
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

On Tue, 25 Sep 2007 13:14:16 -0000, UKP <rockmode@gmail.com> wrote,
quoted or indirectly quoted someone who 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 http://mindprod.com/jgloss/binarysearch.html
for a simpler, slower method than Newton Raphson.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Reply With Quote
  #11 (permalink)  
Old 09-26-2007, 01:58 AM
Michael G Soyka
Guest
 
Posts: n/a
Default Re: Finding a value by approximation / estimation

UKP wrote:
> 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
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: SAS Programming Estimation Form (Pure Technical side) Charles Harbour Newsgroup comp.soft-sys.sas 0 02-09-2006 03:26 PM
Re: SAS Programming Estimation Form (Pure Technical side) Dennis Diskin Newsgroup comp.soft-sys.sas 0 02-09-2006 01:18 PM
SAS Programming Estimation Form (Pure Technical side) Jlu Newsgroup comp.soft-sys.sas 1 02-09-2006 10:16 AM
Re: SASTip - Finding SUGI papers by SAS-L or Tutorials authors Lex Jansen Newsgroup comp.soft-sys.sas 0 04-19-2005 02:57 PM
Re: SASTip - Finding SUGI papers by SAS-L or Tutorials authors Harry Droogendyk Newsgroup comp.soft-sys.sas 1 04-19-2005 01:43 AM



All times are GMT. The time now is 10:08 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.