This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Due: September 11, 2008 CS 257 (Luke Olson): Homework #2 Solutions Problem 1 [Range Reduction] We are developing code for a financial firm and are required to compute tan (10 n ) for various n as a component of our financial model. Use range reduction to show how to compute tan (10 n ) for small n ( n < 5). What happens for large n ( n = 20, 50, 100)? Hint: (Think of the role of the less significant digits in a number, when that number is multiplied by a large number). Hand in pseudocode or matlab code to compute tan (10 4 ) and discuss in a couple of sentences the problem of computing tan (10 20 ). Solution The tan function is periodic. To use range reduction, we have to subtract off integer multiples of , until the value lies in the range 0 to . Using this strategy to compute tan (10 n ), we find an integer k such that 0 (10 n k ) < . Assume we want to calculate (10 n k ) up to two decimal places of accuracy , for n < 5. Since k 10 4 , the digit of that is six places to the right of the decimal point may be two places to the right of the decimal point in k . Therefore we need to use a value of which is accurate up to 6 decimal places.(Using matlab value of pi is fine too. Thats accurate upto 15 decimal digits). Listing 1: Code to compute tan (10 4 ) 1 2 %Value of \pi accurate upto 6 decimal places 3 mypi = 3.141593; 4 x = 104; 5 %Subtract off integer multiples 6 while (x > mypi) 7 x = x  mypi; 8 end 9 %calcute the tan now 10 tan_x = tan (x); 11 fprintf ( tan(104) = tan(%g) = %g\n , x,tan_x); As n gets large, we need more and more digits of accuracy of to compute (10 n k ) up to desired accuracy. In double precision, we can have 52 bits for representation ofaccuracy....
View
Full
Document
This note was uploaded on 07/10/2011 for the course CS 257 taught by Professor Olson during the Spring '08 term at University of Illinois, Urbana Champaign.
 Spring '08
 Olson

Click to edit the document details