Finding the Two-Thirds Root of a Number Using Loops

Hello everyone!

I am trying to create a program that can display the two thirds root of a number that I provide.

I have yet to find any clear explanation of my problem online.

The format of the answer should be like this:

The two thirds root of xxx = xxx.xxx

A two thirds root of x should be equal to x^3/2, correct?

Well I am trying to have the program solve for that x^3/2 without using Math.pow, and instead using a loop of any kind.

Thank you for any help,

tryingtolearn

Re: Finding the Two-Thirds Root of a Number Using Loops

In case you aren't aware of it, Java doesn't have an exponentiation operator. People often say "x^2/3" as a shorthand, but using standard Java they mean something like a call to Math.pow(). ^ really means something quite different in Java.

(Also note that the 2/3 root is 2/3, not 3/2)

(A) The 2/3 root of a number is the cube root of the square of that number.

Think about positive numbers as a simplification that might serve as starting point.

(B) The 2/3 root of zero is zero and the 2/3 root grows as the number whose root is being found grows. What I mean is that big numbers have big 2/3 roots and small numbers have small 2/3 roots.

This suggests we might find a 2/3 root by playing 20 questions. (or rather, n questions where *n* is the limit in the for loop you are supposed to use.)

Code :

make a bigGuess
and a littleGuess
LOOP:
is (bigGuess+littleGuess)/2 too big? If so make bigGuess=(bigGuess+littleGuess)/2
is (bigGuess+littleGuess)/2 too small? If so make littleGuess=(bigGuess+littleGuess)/2

The initial guesses could take advantage of the fact that (C) for numbers bigger than 1 the 2/3 root is less than the number, while for numbers less than 1 the 2/3 root is bigger than the number.

-----

Newton and Halley both came up with iterative methods. But the problem of doubling a cube is much older with geometric (Greek) and iterative approximations (Indian) going back to c400BCE.

Re: Finding the Two-Thirds Root of a Number Using Loops

Quote:

Originally Posted by

**pbrockway2**
In case you aren't aware of it, Java doesn't have an exponentiation operator. People often say "x^2/3" as a shorthand, but using standard Java they mean something like a call to Math.pow(). ^ really means something quite different in Java.

(Also note that the 2/3 root is 2/3, not 3/2)

(A) The 2/3 root of a number is the cube root of the square of that number.

Think about positive numbers as a simplification that might serve as starting point.

(B) The 2/3 root of zero is zero and the 2/3 root grows as the number whose root is being found grows. What I mean is that big numbers have big 2/3 roots and small numbers have small 2/3 roots.

This suggests we might find a 2/3 root by playing 20 questions. (or rather, n questions where

*n* is the limit in the for loop you are supposed to use.)

Code :

make a bigGuess
and a littleGuess
LOOP:
is (bigGuess+littleGuess)/2 too big? If so make bigGuess=(bigGuess+littleGuess)/2
is (bigGuess+littleGuess)/2 too small? If so make littleGuess=(bigGuess+littleGuess)/2

The initial guesses could take advantage of the fact that (C) for numbers bigger than 1 the 2/3 root is less than the number, while for numbers less than 1 the 2/3 root is bigger than the number.

-----

Newton and

Halley both came up with iterative methods. But the problem of doubling a cube is much older with geometric (Greek) and iterative approximations (Indian) going back to c400BCE.

Thank you for your reply, but I am still having trouble understanding.

let's say I wanted to find the 2/3 root of 100.

In the post above it says I should take the square of 100, which is 10, and then find the cube root of 10, which is 3. something.

So I guess I just don't understand the bigGuess/littleGuess concept.

Thanks for your patience and help so far!

tryingtolearn

Re: Finding the Two-Thirds Root of a Number Using Loops

Quote:

let's say I wanted to find the 2/3 root of 100

The 2/3 root of 100 is a number whose cube is 10000 (100 squared). That's (A). In other words we want to find something, where something*something*something is 10000.

That something lies between 1 and 10000. That's (C).

I'll take littleGuess=1 and bigGuess=10000.

LOOP starts:

I check (littleGuess+bigGuess)/2 which is 5000.5

5000.5*5000.5*5000.5 is 125037503750.125 and that's too big (the cube should be 10000). So I revise my guess and make bigGuess=5000.5 and go back to the top of the loop...

-----

I check (littleGuess+bigGuess)/2 which is 2500.75

2500.75*2500.75*2500.75 is 15639066719.171875 and that's still too big. So I make bigGuess=2500.75 and try again...

-----

Check (littleGuess+bigGuess)/2 which is 1250.875. The cube is 1957229434.263671875. bigGuess becomes 1250.875

Check (littleGuess+bigGuess)/2 which is 625.9375. The cube is 245240906.585693359375. bigGuess becomes 625.9375

Check (littleGuess+bigGuess)/2 which is 313.46875. The cube is 30802272.332489013671875. bigGuess becomes 313.46875

Check (littleGuess+bigGuess)/2 which is 157.234375. The cube is 3887250.213802337646484375. bigGuess becomes 157.234375

Check (littleGuess+bigGuess)/2 which is 79.1171875. The cube is 495236.357871532440185546875. bigGuess becomes 79.1171875

Check (littleGuess+bigGuess)/2 which is 40.05859375. The cube is 64281.662188470363616943359375. bigGuess becomes 40.05859375

Check (littleGuess+bigGuess)/2 which is 20.529296875. The cube is 8652.113846175372600555419921875. Too small! bigGuess stays at 40.05859375 and littleGuess becomes 20.529296875.

Check (littleGuess+bigGuess)/2 which is 30.2939453125. The cube is 27801.454087962396442890167236328. (too big) bigGuess becomes 30.2939453125

Check (littleGuess+bigGuess)/2 which is 25.41162109375. The cube is 16409.566686896956525743007659912. bigGuess becomes 25.41162109375

Check (littleGuess+bigGuess)/2 which is 22.970458984375. The cube is 12120.178596764206304214894771576.

-----

The loop constantly evaluates the cube of (littleGuess+bigGuess)/2 and updates one or other of the guesses based on whether the cube is too high or too low (compared with 10000=100^2).

Re: Finding the Two-Thirds Root of a Number Using Loops