solution

*Looking for my answer in Java

Complete the implementation of Sine.java so that it contains static method implementations for the naive and fast sine approximation algorithms. Do not use standard Math library methods such as Math.pow, Math.sin, etc when implementing these algorithms. Do not implement any additional method in this file.

Naive Sine Approximation:

Algorithm: NAIVE – SINE(x,n)

Input:

x – a real number

n – a positive integer

Output:

sum – evaluation of the series expansion of sine

if n < 0 then

ERROR; end

sum := 0;

for i <—- 1 to n do

term := 1

for j <— 1 to 2i – 1 do

term := term * x/j;

end

if 2 divides i then

sum := sum – term;

else

sum := sum + term;

end

end

NAIVE – SINE(x,n) = sum;

Algorithm: FAST – SINE(x,n)

Input:

x – a real number

n – a positive integer

Output:

sum – evaluation of the series expansion of sine

if n < 0 then

ERROR; end

term := 0;

sum := 0;

for i <—- 1 to n do

if 2 divides i then

sum := sum – term;

else

sum := sum + term;

end

term := term * x/2i * x/2i+1;

end

FAST – SINE(x,n) = sum;

Starter Code For Each Method:

public class Sine {
public static double fastSine(double x, int n) throws IllegalArgumentException{
}

public static double naiveSine(double x, int n){

}

}

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!