Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Compute this in Matlab format please. Infinite Series Trigonometric functions ar

ID: 3802259 • Letter: C

Question

Compute this in Matlab format please. Infinite Series Trigonometric functions are usually calculated on computers using truncated infinite series. An infinite series is an infinite set of terms whose is particular function or expression. For example, the infinite series used 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)^(n-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. 1. The MATLAB command for 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(d) function. You are required to use a while loop to determine the calculated sine (infinite series) When calculating the threshold value (actualSine - series Sine) in your while-loop condition, 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, Keep track of which number term you are on to

Explanation / Answer

Matlab code

% Prompting the user to enter the required informations
Deg = input('Enter the value of x in Degrees to evaluate sin(x), x = ');
Pre = input('Enter the precision');
Rad = deg2rad(Deg); % Converting the x value to radians from degree
y = Rad; % first term in the series
sign = 1; % keeping one variable to keet tracking the sign of the terms in the series
n = 1; % variable to keep tracking the numer of terms in the series added
while abs(y - sin(Rad)) > Pre
    fprintf('Number of Terms = %d Current value of sin(%f) = %f ',n,Deg,y);
    sign = sign*-1; % Change the sign for the next term
    n = n+1; % Increase the number of iteration
    y = y+sign*Rad^(2*n-1)/factorial(2*n-1); % adding the next term
end
fprintf('Number of Terms = %d Current value of sin(%f) = %f ',n,Deg,y);

Testing the code

>> sinSeriesSummation
Enter the value of x in Degrees to evaluate sin(x), x = 45
Enter the precision10^-5
Number of Terms = 1   Current value of sin(45.000000) = 0.785398
Number of Terms = 2   Current value of sin(45.000000) = 0.704653
Number of Terms = 3   Current value of sin(45.000000) = 0.707143
Number of Terms = 4   Current value of sin(45.000000) = 0.707106
>> sind(45)

ans =

    0.7071

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote