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

When the numerical approximation error is equal to or less than .000001 then the

ID: 3566173 • Letter: W

Question

When the numerical approximation error is equal to or less than .000001 then the equation has reached its final value. The approximation error is used to show that another addition will not drastically change the final result and an acceptable answer has been reached. Use E >=.000001 for your while loop condition, which is a true statement until the error is smaller than the limit. The error is calculated by the equation below, where Sn is the current term of the summation, and Sn-1 is the previous term of the summation:

Calculate cosTaylor for the following values of x:

Hints: (1) Do not use the function

Explanation / Answer

function [y] = cosTaylor(x)
% approximate cos(x)
% using first n non-zero terms of the Taylor series
% cos(x) = 1 - x^2/2! + x^4/4! + ...
% Input arguments:
% x = real argument to function cos(x)
apx = 0.0;
cos_original=cos(x);
error=1;
i=0;
while(error>0.000001)
apx=apx+(-1)^i*x^(2*i)/factorial(2*i);
error=abs(apx-cos_original);
i=i+1;
end
y=apx;

RESULTS

1.

>> cosTaylor(0)

ans =

1

2.

>> cosTaylor(1/4)

ans =

0.9689

3.

>> cosTaylor(2)

ans =

-0.4161

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote