Question
N=[1,2,3,4,5]; s1=[0,0,0,0,0]; c1=s1;e1=c1; x=pi/3; for i=1:5 for j=0:N(i) s1(i)=s1(i)+(-1)^j*x^(2*j+1)/factorial(2*j+1); end end e1=abs(sin(x)-s1); fprintf('Part a) sin(pi/3) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;s1;e1]) x=pi/4; for
N=[1,2,3,4,5]; s1=[0,0,0,0,0]; c1=s1;e1=c1; x=pi/3; for i=1:5 for j=0:N(i) s1(i)=s1(i)+(-1)^j*x^(2*j+1)/factorial(2*j+1); end end e1=abs(sin(x)-s1); fprintf('Part a) sin(pi/3) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;s1;e1]) x=pi/4; for i=1:5 for j=0:N(i) c1(i)=c1(i)+((-1)^j)*(x^(2*j))/factorial(2*j); end end e1=abs(cos(x)-c1); fprintf('Part b) cos(pi/4) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;c1;e1]) x=-2; e1=[0,0,0,0,0]; for i=1:5 for j=0:N(i) e1(i)=e1(i)+x^j/(factorial(j)); end end e=abs(exp(x)-e1); fprintf('Part c) exp(-2) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;e1;e])
I have codes for PART 2. I need PART 4
HW6P2 (15 points) The following are infinite series representations of the functions sine, cosine, and the exponential. 2n+1 sin(x)= ? (-1)" 2n cos(x) -(-1)" (2n)! n-0 Performing the summation only to N terms is called a partial sum and is denoted by SN. n:0 Within your script file, use nested for loops to compute the first 5 partial sums with N- 2, 3, 4 and 5 in order to estimate the following: a) sin(/3) b) cos(t/4) 2 Assuming that the built-in MATLAB functions sin (), cos (, and exp () return the exact values, calculate the absolute difference between the value of the function determined by your code and the MATLAB function. Print out your results, and ONLY your results, to the command window as seen below where S(N) is the partial sum out to N values. PART a) sin(pi/3) -> MUST INCLUDE THIS LINE IN YOUR OUTPUT S (1) 0.8558007816, Error 1.022462221932130E-02 S (2)0.8662952838, Error-2.698800023961390E-04 , Error - Error HINT: Use fprintf inside the outside loop with format i for N (1, 2, ..., 5), format 10f for the value of SN, and format.15E for the absolute error. You can use the MATLAB function factorial () to determine the factorial; however, DO NOT use the sum () function in MATLABStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started