Homework 4 Math Methods for Mechanical Engineers (MECH.3610) The Maclaurin serie
ID: 2258855 • Letter: H
Question
Homework 4 Math Methods for Mechanical Engineers (MECH.3610) The Maclaurin series expansion for e* is computed as follows: ex = 1+2+ 2t · 31 The function IterMeth calculates the exponential using this series. This code can be downloaded from the textbook web page or Blackboard. Make a copy of the function IterMeth and modify it to calculate a new approximation (x In (a) x In(a)) t a" = ex Inda-1 + x1n (a) + (x ln(a), (xln(a))3 3! Include the following modifications: 1. Add an additional input parameter to the input of function IterMeth and rename the function. function [fx,ea,iter] IterMeth HW4(a,x,es,maxit) 2. Modify the comment lines to reflect the changes made to the function. Modify the default settings on lines 14 and 15, since there are now 4 possible input values: 3. if narginExplanation / Answer
function [fx,ea,iter] = IterMeth_HW4(a,x,es,maxit)
% Maclaurin series expansion function for a^x
% [fx,ea,iter] = IterMeth_HW4(a,x,es,maxit)
% input:
% a = value of the number for which power needs to be calculated
% 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<3|isempty(es),es=0.0001;end
if nargin<4|isempty(maxit),maxit=50;end
% initialization
iter = 1; sol = 1; ea = 100;
% iterative calculation
while (1)
solold = sol;
sol = sol + (x*log(a)) ^ 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
OUTPUT:
>> m = IterMeth_HW4(2,0.5,0.0001,50)
m =
1.414213557004892
>> n = sqrt(2)
n =
1.414213562373095
>> error = (n-m)*100/n
error =
3.795892896314411e-07
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.