Exponentiation
A curious omission from this collection of mathematical functions is the exponentiationfunction for computing quantities like 23 or 100:33. However, we have the tools necessary
to build our own. The C programming language uses the function, pow(), to perform
exponentiation. For example, 23 = pow(2,3), and 100:33 = pow(10,0.33). If we have need
of exponentiation, we simply take advantage of the properties of logarithms base e and the
exponential function, ex. Recall that
loge(xa) = a loge x:
Also, recall that loge(ex) = x. Combining these two properties, we have
xa = ea loge(x):
In RobotC, ex = exp(x), and loge(x) = log(x). Therefore, the function in Listing 5.6 will
give us the standard C exponentiation function.
float pow( float x, float a) {
return exp (a*log(x ));
}
Listing 5.6: The standard C language exponentiation function built of available RobotC
functions.
No comments:
Post a Comment