Question: function [fx,ea,iter] = IterMeth(x,es,maxit) % Maclaurin series of exponential function % [fx,ea,iter] = IterMeth(x,es,maxit) % input: % x = value at which series evaluated %

function [fx,ea,iter] = IterMeth(x,es,maxit) % Maclaurin series of exponential function % [fx,ea,iter] = IterMeth(x,es,maxit) % input: % x = value at which series evaluated % es = stopping criterion (default = 0.0001) % maxit = maximum iterations (default = 50) % output: % fx = estimated value % ea = approximate relative error (%) % iter = number of iterations

% defaults: if nargin<2|isempty(es),es=0.0001;end if nargin<3|isempty(maxit),maxit=50;end % initialization iter = 1; sol = 1; ea = 100; % iterative calculation while (1) solold = sol; sol = sol + x ^ iter / factorial(iter); iter = iter + 1; if sol~=0 ea=abs((sol - solold)/sol)*100 end if ea<=es | iter>=maxit,break,end end fx = sol; end

(a) Modify the provided IterMeth code so that instead of passing scalar values, it accumulates vectors containing all values of the estimated value, Va, the true relative percent error, t%, and approximate relative percent error, a%. (b) Generate a script that uses your modied IterMeth function and then plots both t% and a% as a function of iteration number. (c) How many iterations (and therefore how many terms in the Maclaurin series expansion) does it require to generate an estimated value with 11 signicant digits? (Use s = (0.510(2n))%)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!