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

The Taylor series expansion of the natural log function ln ( x ) is given by ln

ID: 3939449 • Letter: T

Question

The Taylor series expansion of the natural log function ln ( x ) is given by ln (x) = ( x 1 ) ( x 1 )^2/2 + ( x 1 )^3/3 ( x 1 )^4/4 + ( x 1 )^5/5 ... This expansion is valid for values of x where 0 < x 2 . Write a Matlab function ( mylog ) that will calculate the natural log function using this expansion. This is an infinite sum, but your function should stop the summation at step k, when ( x 1 )^k/k < tol where tol is a user - supplied value. Your function should take two inputs. You must check for nonsensical input values. For the factorial, you should use your my factorial (n) function which returns n!. Your function ( mylog ) should return two values – the approximation of ln ( x ) and the num ber of steps k. Submit one function : mylog . m .

Explanation / Answer

Here is the code fro you:

function [sum, steps] = mylog(x, tol)

sum = x - 1;

steps = 1;

sign = -1;

term = (x - 1)^steps / steps;

while(term >= tol)

steps = steps + 1

term = sign * (x - 1)^steps / steps;

sum = sum + term;

sign = sign * -1;

end

end

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