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

In Matlab Code. A common (but not efficient) Taylor series expansion lets us app

ID: 3028598 • Letter: I

Question

In Matlab Code.

A common (but not efficient) Taylor series expansion lets us approximate the arctangent function using tan^-1(x) = sigma_n=0^m (-1)^n x^2n+1/2n+1 which has m+1 terms and is valid for x in [-1, 1]. The approximation becomes exact as m rightarrow infinity. Write a Matlab script that prompts the user for x and the highest order term, m and reports the approximated value of arctan(x) using a counting (for) loop. Note that, since the tangent of pi/4 (45 degree) is 1, we can use 4 tan^-1(x) = pi as an easy check on how close the approximation is getting. Of course, it is also easy to check using a calculator or Matlab's atan function. (The filename should be hw06_02. m.) Create a revised version of your code from 2) so that it asks for x but does not ask for the highest order term, m. Instead, it iterates enough times so that the absolute value (try Matlab's abs function) of the approximation of arctan(x) has changed by less than some tolerance, which you declare as a constant. This is best done using a while (condition) loop or a while loop with a conditional break statement. For testing, report the approximated value and the number of iterations to find arctan(1) using tolerances of 10^-2 and 10^-3. (The filename should be hw06_03. m.)

Explanation / Answer

a.)

Matlab code :

function sum=hw06_02(x,m)

sum=1;
if m~=1
for n=1:m
sum=sum+((-1)^(n)*x^(2*n+1)/(2*n+1));
end

end

end

b.)

Matlab code :

function [sum1,n]=hw06_03(x,e)

sum1=1;
error=0;
n=1;
while error>=0
sum0=sum1;

sum1=sum1+((-1)^(n)*x^(2*n+1)/(2*n+1));
n=n+1;
error=abs(sum1-sum0);
if error<e
break
end
end
end

For testing i have taken e=10-2, then it gave us   sum1(approximate sum)=0.7903 and the number of terms n=51

again i have taken e=10-3, then it gave us   sum1(approximate sum)=0.7859 and the number of terms n=501

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