Download the MATLAB function IterationMethod.m from the link: https://drive.goog
ID: 3750440 • Letter: D
Question
Download the MATLAB function IterationMethod.m from the link: https://drive.google.com/file/d/1KVqIeXMynjNQ2frJyKnAiTGLzGSZ--QI/view?usp=sharing.
Revise the function to compute the Taylor series of the inverse tangent function:
Check the answer using the atan function in MATLAB
Test for a case when the program achieved the user-specified accuracy and for a case when the number of iterations exceeded the user-specified limit. Copy and paste the workspace results showing values computed with the Taylor series, values computed using atan, and the true error. Here are some sample executions of a main program that display the results:
7! 2n +1Explanation / Answer
Given below is the modified code.
function [fx,Error,iter] = IterationMethod(x,es,maxit)
% This function computes the Taylor series of the inverse tangent function
% [fx,Error,iter] = IterationMethod(x,es,maxit)
% input:
% x = value at which exponential series is evaluated
% es = stopping criterion
% maxit = maximum number of iterations allowed
% output:
% x_est = estimated value
% Error = approximate error
% Niter = number of iterations
% Modification of IterMeth.m on page 94 of the text book
% initialization
iter = 0; % current iteration number
solution = 0;
Error = 1; % Error = 1 as the starting point
% iterative calculation
while (Error > es && iter <= maxit)
solution_old = solution; % save previous value
solution = solution + (-1)^(iter) * x^(2*iter+1) / (2*iter+1) ;
iter = iter + 1; % increment the iteration number
Error=abs(solution - solution_old);% calculation of error
end
if iter > maxit
display(' ***********************************************')
display(' ** solution not found to specified accuracy **')
display(' ***********************************************')
end
fx = solution;
=============================
I tested it using
> [f, er, n] = IterationMethod(0.6, 1e-06, 100)
output is
f = 0.540419414949369
er = 3.43360966548190e-07
n = 12
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.