. An alternative way for calculating sin(x) is to use its Taylor series as the f
ID: 2073709 • Letter: #
Question
. An alternative way for calculating sin(x) is to use its Taylor series as the following: sin(x)-x-+ Create a function named "sin_taylor" in MATLAB. This function takes two inputs. First input is the angle, and the second input determines the number of terms in Taylor series for approximation. Check the fidelity of your function by running sin-taylor( 7) and compare it with the exact value of it. Hint: "factorial" is a built-in function that you can use for calculating factorial of an integer number. Use MATLAB documentation to find more about it. 31S!Explanation / Answer
function s=sin_taylor(x,n)
s=0;
k=0;
for i= 1:2:n
s=s+power(-1,k)*((power(x,i))/(factorial(i)));
k=k+1;
end
comp=sin(pi/6)-s;
fprintf('Fidelity of the function is %d',comp)
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.