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

The values of sin(x) and cos(x) can be approximated by the following Taylor seri

ID: 3864559 • Letter: T

Question

The values of sin(x) and cos(x) can be approximated by the following Taylor series: sin (x) = x - x^3/3! + x^5/5! - x^7/7! + ...... cos(x) = 1- x^2/2! + x^4/4! - x^6/6! + ...... Or in compact forms, sin(x) = sigma^infinity _k = 1 (-1)^k+1 x^2k - 1/(2k - 1)! cos(x) = sigma^infinity _k = 1(- 1)^k-1 x^2(k-1)/(2(k-1))! Recall the symbol ! stands for factorial. The more terms you have in the series, the more accurate the approximation for the values of sin(x) or cos(x). However, it is not necessary or not possible to include an infinite number of terms to calculate their values. Start with the first two terms in the summation series. Then, add an additional term Into the series one by one. When the absolute difference between the new summation and the previous summation (without the new term) is less than 0.001, you can stop and obtain an approximate value for sin(x) or cos(x). Write a MATLAB script that follows the above algorithm to estimate the values for sin (x) and cos(x) for x in the range of [0,4 pi]. Your script should also generate a graph with two subplots side by side, showing x versus the approximate results of sin(x) and cos(x) you obtained from the above algorithm with red circle markers. At least 20 values of x should be considered in the approximation. Then, in each subplot, draw another blue dashed curve for x versus the exact values of sin(x) and cos(x), which are calculated by the MATLAB built-in function sin() and cos(x), respectively. The same x values should be considered here as above. You need to title and label your plot properly. A legend should be included to distinguish the approximate results and exact results.

Explanation / Answer

I am only providing you the code because, as it's your homework you should only use this site as a guide and not for complete answers:

function taylorplot(f,a,left,right,n)

%TAYLORPLOT: MATLAB function M-file that takes as input

%a function in inline form, a center point a, a left endpoint,

%a right endpoint, and an order, and plots

%the Taylor polynomial along with the function at the given order.

syms x

p = vectorize(taylor(f(x),n+1,a));

x=linspace(left,right,100);

f=f(x);

p=eval(p);

plot(x,f,x,p,’r’)

f=inline(’sin(x)’)

f = Inline function: f(x) = sin(x)

taylorplot(f,0,0,4*pi,20) // after 20 times the summation will not be of any significant value

%For plotting cos x

f=inline(’cos(x)’)

f = Inline function: f(x) = cos(x)

taylorplot(f,0,0,4*pi,20) // after 20 times the summation will not be of any significant value