You need to compute sinx for x 0 on a lowlevel processorco

You need to compute sin(x) for x ? [0, ?] on a low-level processor/compiler. Only the operations +, ?, ×, ÷ are available. You’ve been told that it only has “roughly 6 digits” of accuracy. Your coworker has written the following pseudo-code (essentially MATLAB).

input x;
x3 = x ? x ? x;
x5 = x3 ? x ? x;
x7 = x5 ? x ? x;
x9 = x7 ? x ? x;
x11 = x9 ? x ? x;
x13 = x11 ? x ? x;
f3 = 6;
f5 = 5 ? 4 ? f3;
f7 = 7 ? 6 ? f5;
f9 = 9 ? 8 ? f7;
f11 = 11 ? 10 ? f9;
f13 = 13 ? 12 ? f11;
y = x ? x3/f3 + x5/f5 ? x7/f7 + x9/f9 ? x11/f11 + x13/f13;

This code will run many, many times, and so needs to be fast. Using what you know about Taylor series and Horner’s Method, can you im- prove on your coworker’s code? (Do not go so far as table look ups and/or if/then logic.) Indicate what you would do. This problem is somewhat open-ended.

2. You need to compute sin(x) for x E [0, ] on a low-level processor/compiler. Only the operations +,-, x,÷ are available. You\'ve been told that it only has \"roughly 6 digits\" of accuracy. Your coworker has written the following pseudo-code (essentially MATLAB) input x; f5 = 5 * 4 * f3; /7=7*6*/5: /9=9*8*/7: /11=11*10*/9; /13 13 * 12 * f11; This code will run many, many times, and so needs to be fast. Using what you know about Taylor series and Horner\'s Method, can you im prove on your coworker\'s code? (Do not go so far as table look ups and/or if/then logic.) Indicate what you would do. This problem is somewhat open-ended

Solution


Let me number the lines of pseudocode so that it makes it easier to explain.

1.   input x,
2.   x3 = x x x;
3.   x5 = x3 x x;
4.   x7 = x5 x x;
5.   x9 = x7 x x;
6.   x11 = x9 x x;
7.   x13 = x11 x x;
8.   f3 = 6;
9.   f5 = 5 4 f3;
11.   f7 = 7 6 f5;
12.   f9 = 9 8 f7;
13.   f11 = 11 10 f9;
14.   f13 = 13 12 f11;
15.   y = x x3/f3 + x5/f5 x7/f7 + x9/f9 x11/f11 + x13/f13;

The line 1 till 8 seems fair enough, there is nothing much to modify.

Since this pseudocode assumes n=13, the denominators in the calculation of y can be considered constants. That way, we can reduce the moremory storage and unnecessary multiplication. We can omit the lines 8-14 and modify the line 15 as follows,

y = x - x3/6 + x5/120 - x7/5040 + x9/362880 - x11/39916800 + x13/6227020800


So the modified pseudocode would be,

1.   input x,
2.   x3 = x x x;
3.   x5 = x3 x x;
4.   x7 = x5 x x;
5.   x9 = x7 x x;
6.   x11 = x9 x x;
7.   x13 = x11 x x;
8.   y = x - x3/6 + x5/120 - x7/5040 + x9/362880 - x11/39916800 + x13/6227020800

If needed,

we can still increase the performance by reducing the number of digits in the denominators which are huge numbers as this program is needed to have only 6 digits of accuracy.
Removing a few digits will only affect the last few digits of the decimal part in the final answer.

i.e y = x - x3/6 + x5/120 - x7/5040 + x9/362880 - x11/3991680 + x13/6227020

You need to compute sin(x) for x ? [0, ?] on a low-level processor/compiler. Only the operations +, ?, ×, ÷ are available. You’ve been told that it only has “ro
You need to compute sin(x) for x ? [0, ?] on a low-level processor/compiler. Only the operations +, ?, ×, ÷ are available. You’ve been told that it only has “ro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site