Register and join over 40,000 other developers!
Recent Topics

Print specific values from dictionary with a specific key name
Siten0308  Jun 20 2019 01:43 PM

Learn algorithms and programming concepts
johnnylo  Apr 23 2019 07:49 AM

Job Gig PHP Form Needed
PJohnson  Apr 18 2019 03:55 AM

How to make code run differently depending on the platform it is running on?
xarzu  Apr 05 2019 09:17 AM

How do I set a breakpoint in an attached process in visual studio
xarzu  Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
 networking
 Managed C++
 stream
 console
 database
 authentication
 Visual Basic 4 / 5 / 6
 session
 Connection
 asp.net
 import
 syntax
 hardware
 html5
 array
 mysql
 java
 php
 c++
 string
 C#
 html
 loop
 timer
 jquery
 ajax
 javascript
 programming
 android
 css
 assembly
 c
 form
 vb.net
 xml
 linked list
 login
 encryption
 pseudocode
 calculator
 sql
 python
 setup
 help
 game
 combobox
 binary
 hello world
 grid
 innerHTML
Program To Find 2/3 Root Of Number X Using Only Loops? Help Please :/
Started by tryingtolearn, Jul 08 2012 01:55 PM
loop
1 reply to this topic
#1
Posted 08 July 2012  01:55 PM
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 ** = **.**
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
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 ** = **.**
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
#2
Posted 08 July 2012  03:49 PM
I don't know why you would, as even C or assembly usually don't, but if you're trying to learn then it should actually be pretty easy, especially given that 3/2 is a rational number.
First of all, to calculate x^(3/2), let's take the fact that x^(a/b) = (x^a)^(1/b). This way the program just needs to find x^a, and then finding the b root of x should be as easy as implementing Newton's Method of Approximation.
We'll need to find the intersection of f(t)=t^b and g(t)=X . The reason for this is that X is what we're trying to find the b root of and t^b is a variable to the b power (we're trying to find t; t^b = X > t = X^(1/b)). To find the intersection, we manipulate the equation to form the following:
t^b  X = 0
We can then use Newton's Method of Approximation to find what t must be equal to, given that t is the variable and all other symbols are constant.
Newton's method is like this:
x= x  f(x) / f'(x)
The way we follow that is put in a random value (a guess) for x and evaluate the right side of the equation. Then we take that result and put it in for x. We repeat the operation, using the new x for the right side of the equation and then plug that result in for x. We keep going until we get close enough to the actual answer (the rate of change will significantly decrease as the x gets close to the actual answer).
That can be thought of as:
float now_x= 8; // Just a guess value.
float previous_x= 100;
do {
previous_x = now_x
now_x = now_x  f(now_x) / f'(now_x)
} while (... until now_x is close enough to previous_x ...);
Where f(t) is, in our case, is (t^b  X) , and f'(t) is the derivative of f(t). The derivative with respect to t of (t^b  X) is equal to (b * t^(b  1)) .
What you'll need to do is write a function or a procedure that will do those calculations (think of a value (a guess) for now_x, loop until now_x close enough to previous_x, and in the loop {set previous_x to now_x and then calculate the new value for now_x}) to find the square root (b = 2) of X. Again, to get X you just need to cube x (easy enough to do).
First of all, to calculate x^(3/2), let's take the fact that x^(a/b) = (x^a)^(1/b). This way the program just needs to find x^a, and then finding the b root of x should be as easy as implementing Newton's Method of Approximation.
We'll need to find the intersection of f(t)=t^b and g(t)=X . The reason for this is that X is what we're trying to find the b root of and t^b is a variable to the b power (we're trying to find t; t^b = X > t = X^(1/b)). To find the intersection, we manipulate the equation to form the following:
t^b  X = 0
We can then use Newton's Method of Approximation to find what t must be equal to, given that t is the variable and all other symbols are constant.
Newton's method is like this:
x= x  f(x) / f'(x)
The way we follow that is put in a random value (a guess) for x and evaluate the right side of the equation. Then we take that result and put it in for x. We repeat the operation, using the new x for the right side of the equation and then plug that result in for x. We keep going until we get close enough to the actual answer (the rate of change will significantly decrease as the x gets close to the actual answer).
That can be thought of as:
float now_x= 8; // Just a guess value.
float previous_x= 100;
do {
previous_x = now_x
now_x = now_x  f(now_x) / f'(now_x)
} while (... until now_x is close enough to previous_x ...);
Where f(t) is, in our case, is (t^b  X) , and f'(t) is the derivative of f(t). The derivative with respect to t of (t^b  X) is equal to (b * t^(b  1)) .
What you'll need to do is write a function or a procedure that will do those calculations (think of a value (a guess) for now_x, loop until now_x close enough to previous_x, and in the loop {set previous_x to now_x and then calculate the new value for now_x}) to find the square root (b = 2) of X. Again, to get X you just need to cube x (easy enough to do).
Regards,
RR
RR
Also tagged with one or more of these keywords: loop
Language Forums →
PHP →
Content and title won't show on certain page in WordpressStarted by Mello, 05 Jan 2016 wordpress, php, loop 


Language Forums →
C# →
Create Staircase with Nested LoopsStarted by StainedSilva, 12 Mar 2015 nested, loop, staircase 


Language Forums →
Other Languages →
Bash / Shell Scripting →
Here is a task... Find Nothing :PStarted by ShaunPrawn, 07 Aug 2014 random, bash, loop, number and 1 more... 


General Forums →
General Programming →
Trying to do a working loopStarted by Error, 23 Jun 2014 loop, java 


Language Forums →
PHP →
Problem in displaying data inside table formatStarted by newphpcoder, 25 Jul 2013 php, table form, loop 

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download