Go to Post You can lead a horse to water but you can't make it drink. Our job is to make the horse thirsty. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 10-02-2012, 05:23 PM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Power Function

I was wondering the best way to make a power function for any number. I came up with the conclusion of using Newton's root finding Method which computes is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function. I was able to find that this worked perfectly on a calculator, but it didn't work when you program it. This is because the long, double, and float data types are not long enough. A bigDecimal is needed, but the FRC Java which is Java ME doesn't not have that class. Is there a way to work around this? Thanks a lot.
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote
  #2   Spotlight this post!  
Unread 10-02-2012, 05:44 PM
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Power Function

Isn't there already a power function in Java.lang.Math?

http://docs.oracle.com/javase/1.5.0/...e,%20double%29
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #3   Spotlight this post!  
Unread 10-02-2012, 05:48 PM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Re: Power Function

Yes in regular Java but not FRC version. Also in regular java its function is native so the class has no copyable code.
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote
  #4   Spotlight this post!  
Unread 10-02-2012, 05:52 PM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,997
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Power Function

Quote:
Originally Posted by tyandjel94 View Post
I was wondering the best way to make a power function for any number. I came up with the conclusion of using Newton's root finding Method which computes is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function. I was able to find that this worked perfectly on a calculator, but it didn't work when you program it. This is because the long, double, and float data types are not long enough. A bigDecimal is needed, but the FRC Java which is Java ME doesn't not have that class. Is there a way to work around this? Thanks a lot.
I suspect you did not program it correctly. Double precision floats should have adequate resolution for this.

But there may be a better way. Does the Java FRC runtime math library support logarithms and exponentiation?

If so, there's a simple solution:

You want to compute:

power = base^x

... for any positive real base and x, correct?

To do so, substitute e^ln(base) for base to get:

power = e^(x*ln(base))


Reply With Quote
  #5   Spotlight this post!  
Unread 10-02-2012, 06:05 PM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Re: Power Function

No it doesn't have log or exponent functions. And no the number of precision has to be more than the max value of double (1.7976931348623157 *10^308). If it's not then the program keeps running down to the base value, then get a runtime error.
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote
  #6   Spotlight this post!  
Unread 10-02-2012, 07:06 PM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,997
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Power Function

Quote:
Originally Posted by tyandjel94 View Post
No it doesn't have log or exponent functions.
http://www.chiefdelphi.com/forums/sh...63&postcount=4

Quote:
Originally Posted by Jared341 View Post
Most of the underlying math primitives (e.g. forward and inverse trig, exponents, square roots, etc.) are present in the FRC Java implementation - they went ahead and implemented more than the bare bones J2ME spec requires (albeit in a different package structure than J2SE...you need to do some digging to find where some of the classes live)
Reply With Quote
  #7   Spotlight this post!  
Unread 10-02-2012, 07:48 PM
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Re: Power Function

Ok thanks. I found it under squawk. Do you know if there are arrayLists, decimalFormat or java.net classes? Thanks again for your help.
__________________
-Tyler
Team 1647 Iron Devils

Last edited by tyandjel94 : 10-02-2012 at 08:05 PM.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 07:26 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi