Infinite Series Trigonometric functions are usually calculated on computers usin
ID: 3109189 • Letter: I
Question
Infinite Series Trigonometric functions are usually calculated on computers using truncated infinite series. An infinite series is an infinite set of terms whose sum is a particular function or expression. For example, the infinite series used to evaluate the sine of a number is sin(x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! - or sin(x) = sigma^n_n = 1 (-1)^(x - 1) x^(2n - 1)/2n - 1)! where x is in units of radians. Since a computer does not have enough memory(or time, obviously) to add an infinite number of terms for every sine that is calculated, the infinite series truncates after a finite number of terms, determined by a pre-defined precision. N represents the number of terms. For program 4, write a MATLAB program that prompts for degrees, and then prompts for a precision. Determine the number of terms required to evaluate the sine for the given precision as compared to MATLAB's sin(x) function (x is also in units of radians). For each iteration, output the current value of the series as shown in the Sample Output. The MATLAB command for x is pi. The MATLAB command for sine in radians is sin(x). The MATLAB command for factorial is factorial(x). Convert degrees (deg) to radians using Matlab's deg2rad(x) function. You are required to use a while loop to determine the calculated sine (infinite series). When calculating the threshold value (actualsine-seriesSine) in your while loop use the absolute value of the difference: abs(x) Terms in the series alternate SIGN. All odd number terms are positive, and even number terms are negative, determine if you ADD or SUBTRACT. For example, x^2/2! is the fourth term in the sine series, therefore it is SUBTRACTED from the current series sine. The power and the subsequent factorial both increase by factors of 2. Keep track of the current power or each iteration of the while loop by adding 2 each time.Explanation / Answer
Here is the code:
syms n x
f(n,x) = ((-1)^(n-1))*((x^((2*n)-1))/(factorial((2*n)-1)));
degree = input('Enter the degrees for which to find the sine:');
precision = input('Enter the precision for the infinite sine series:');
actual = sin(deg2rad(degree));
X = sprintf('Actual sin[%6.3f-degrees]=%f',degree,actual);
disp(X)
disp('........................................................')
stop = false;
i = 1;
while ~stop
cur_value = vpa(symsum(f(n,deg2rad(degree)), n, 1, i),8);
X = sprintf('Current value of sine series is %f',double(cur_value));
disp(X)
if abs(actual-cur_value) < precision
stop = true;
end
i = i+1;
end
X = sprintf(' Actual sin[%6.3f-degrees]=%f',degree,actual);
disp(X)
X = sprintf('Series sin[%6.3f-degrees]=%f using %d iterations',degree,double(cur_value),i-1);
disp(X)
DO THUMBS UP ^_^