/* Start with the function Y = 1/X sin(X). We want the inverse of this function. That is given a value for Y find the X that corresponds to this Y value. The equation Y = 1/X sin(X) can not be inverted analytically so this routine will use a method of successive approximation to determine the value of X that corresponds to the supplied value of Y. This work is greatly simplified because this routine only needs to be able to work over a limited range of X. This range is the first quadrant were X can have any value in the range 0 <= X <= Pi/2 i.e. 0 to 90 degrees. In this range of X, Y takes the values 1 at X=0 (0 degrees) through 2/Pi at X = Pi/2 (90 degrees). Through this range of X, Y is monotonically falling from its value of 1 down to 2/Pi. The very well behaved nature of this function in this range makes it easy to use successive approximation. The following algorithm is used: The routine is called and passed the value of Y. Set working fraction to 1/2. Set the guessed value of X to Pi/4 i.e. 45 degrees. 1. Test is Y is <=> 1/X sin(X) using the guessed value of X. 2. If Y < 1/X sin(X) then the new guessed value of X equals the current guessed value + (Pi * Working_Fraction). New Working_Fraction equals 1/2 of the current Working_Fraction. 3. Else If Y > 1/X sin(X) then the new guessed value of X equals the current guessed value - (Pi * Working_Fraction). New Working_Fraction equals 1/2 of the current Working_Fraction. 4. Exit if Working_Fraction is small enough, else go to step 1. The advantage of this method of starting in the middle and each time dividing the step size by 2 is that one does not have to worry about what to do at X = 0 where the function becomes undefined. Calculate and display 1/X sin(X) for 0 < X < PI/2 */ #include #include main () { float lower, upper, step ; float temp_1, temp_2, temp_3 ; lower = 0.025 ; upper = 1.550 ; step = 0.025 ; printf ("\n Degrees, Radians, 1/X sin(X) \n" ); temp_1 = lower ; while (temp_1 <= upper) { temp_2 = ( 1.0 / temp_1 ) * sin(temp_1) ; temp_3 = temp_1 * 57.295779 ; printf (" %4.2f %4.3f %6.3f \n", temp_3, temp_1, temp_2 ); temp_1 = temp_1 + step ; } }