Algorithm for Simple Fractional ExponentsDate: 03/14/2002 at 08:00:04 From: Matthew Rae Loutner Subject: Need Algorithm for Resolving Simple Fractional Exponents. Dr. Math, I hope you can help. I am writing a computer program with a programming language that cannot do higher math. How can I explain to my program how to resolve simple fractional exponents using only addition, subtraction, multiplication, division, square, and square root? (I can put repetitive loops in the program, so repetition is not a problem.) The problem will be in the form of X = 1.49^1/2 up to say, X = 1.73^1/30. I just need to solve these for X. I know there is a common algorithm that is used for this, but I can't locate it anywhere. I haven't even seen the problem addressed. Thanks. Matthew Date: 03/14/2002 at 08:34:37 From: Doctor Jerry Subject: Re: Need Algorithm for Resolving Simple Fractional Exponents. Hi Matthew, One way of calculating a^{1/n} is to set x = a^{1/n} x^n = a and so x will be a root of the equation f(x) = x^n-a. So, one way is to apply Newton's method. This uses the idea of derivative from calculus. You also need a half-way decent first approximation to the root. Another way is to use logs and exponentials. x = a^{1/n} ln(x) = (1/n)*ln(a) After calculating log(a), you can do ln(a)/n = N. Then you will need to exponentiate each side: e^{ln(x)} = e^N So if you use this way, you will need to have an algorithm to calculate ln and exp. For this you can use the CORDIC algorithm. Here's something I wrote a while back. For more detail see How Do Calculators Calculate? http://www.math.utep.edu/Faculty/helmut/cordic/wcordic.html Calculators use what is called the CORDIC method. TI and HP use several stored constants and calculate the values of several sequences of numbers, using only addition and multiplication. They continue the calculation until sufficient accuracy is obtained. The algorithm looks like this: I'll use x_k to mean x sub k and x_{k+1} to mean x sub k+1, and so on. Let x_{k+1} = x_k - d_k*y_k*2^(-k) y_{k+1} = y_k + d_k*x_k*2^(-k) z_{k+1} = z_k - d_k*s_k The numbers d_k are equal to the sign of z_k (if z_k >= 0, d_k = 1; if z_k<0, then d_k = -1). Also, s_k = arctan(2^(-k)). The numbers s_k are permanently stored in the calculator, maybe up to k = 50 or so. Starting values for the calculation are calculated. If z_0 = t is given, where t is a given angle (in radians), then y_0 = 0 and x_0 = cos(s_0)*cos(s_1)*...*cos(s_{47}). As k increases, x_k approaches cos(t) and y_k approaches sin(t). - Doctor Jerry, The Math Forum http://mathforum.org/dr.math/ |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/