The sine function can be evaluated by the following infinite series as (where th
ID: 1856718 • Letter: T
Question
The sine function can be evaluated by the following infinite series as (where the angle x is given in radians): sin x = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + ..... (a)Create a function M-file mysin1 that takes the angle x (in degrees) and the number of terms n as the input, and returns sin(x) as the output using n number of terms in the above expansion. Test your function with x=1.53, and n=10. (b)Create a second function M-file mysin2that takes the angle x (in radians) and the significant digits sigdig as the input, and returns sin(x) correct to sigdig significant digits as the output. Test your function to find sine of 2.24 correct to 14 significant digits. In both cases, for each term in the expansion, display the term #, contributions from the terms, and the actual error (absolute error, not the relative one) using fprintf statement. The true or actual value can be calculated from MATLABExplanation / Answer
the mysin1 function is written below. copy and save it as .m file and run it.
function [ y ] = mysin1( x,n )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
syms t;
double y;
y=x;
t=3;
p=1;
while t<=n
y=y+((-1)^p)*((x^t)/factorial(t));
t=t+2;
p=p+1;
end
display(double(y));
end
b>
mysin2 is written here.
function [ y ] = mysin2( x,n )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
syms t;
double y;
double g;
double e;
y=x;
t=3;
p=1;
while t<=n
g=((-1)^p)*((x^t)/factorial(t));
y=y+g;
t=t+2;
p=p+1;
e=abs(y-sin(x));
end
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.