Engineering
Starting with the simplest approximation, cos x = 1, add terms one at a time to estimate cos(/3) (see Problem 2 in Lecture 5). (a) After each new term is added, compute the true and approximate percent relative errors. Use a calculator to determine the true value. Add terms until the absolute value of the approximate error estimate falls below an error criterion conforming to two significant figures. (b) Rename M-file function Maclaurin.m (available in Files/Lectures/05) to Maclaurin_cos.m, modify, and adapt it for evaluating the Maclaurin series expansion for cos x. Implement fprintf inside while loop to display for each iteration the following output: iteration number, approximate value of cos(/3), true percent relative error, approximate percent relative error. Report your M-file and output results for cos(/3).function [fxa,fxt,et,ea,iter] = Maclaurin(x,es,maxit)% Maclaurin series of exponential function% [fxa,fxt,et,ea,iter] = Maclaurin(x,es,maxit)% input:% x = value at which series evaluated% es = stopping criterion (default = 0.0001)% maxit = maximum iterations (default = 100)% output:% fxa = estimated value% fxt = true value% et = true relative error (%)% ea = approximate relative error (%)% iter = number of iterations% defaults:if nargin < 2||isempty(es),es = 0.0001;endif nargin < 3||isempty(maxit),maxit = 100;end% initializationiter = 1; sol = 1; ea = 100;fxt = exp(x);et = abs((fxt - sol)/fxt)*100;% iterative calculationwhile (1)solold = sol;sol = sol + x^iter/factorial(iter);iter = iter + 1;if sol~= 0ea = abs((sol - solold)/sol)*100;et = abs((fxt - sol)/fxt)*100;endif ea= maxit,break,endendfxa = sol;end