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

Infinite Series Trigonometric functions are usually calculated on computers usin

ID: 3109098 • 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! ellipsis 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.

Explanation / Answer

clc;
clear all;
close all;
format long
n=input('Enter the angle in deegree ');
x=deg2rad(n);
f_act=sin(x);
sum=0;
pre=10^(-6);
n=1;
k=1;
while(abs(sum-f_act)>pre)
sum=sum+(-1)^(k+1)*x^n/factorial(n);
f_itr(k)=sum;
n=n+2;
k=k+1;
end
display('Actual value of function sin(x)');
f_act
display('Value of serie sat each iteration ');
f_itr'
display('number of term required to reach given precision is ');
k

output:

Enter the angle in deegree 45
Actual value of function sin(x)

f_act =

0.707106781186547

Value of serie sat each iteration

ans =

0.785398163397448
0.704652651209168
0.707143045779360
0.707106469575178

number of term required to reach given precision is

k =

5