Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve using MATHLAB Program. Lesson 8 Problem 22: Natural Log The Taylor Series for the In(x) for any x in the range 0x2 is
Please solve using MATHLAB Program.
Lesson 8 Problem 22: Natural Log The Taylor Series for the In(x) for any x in the range 0x2 is given by: (x21), (-1). (x41). (-1)n+1 ln(x) - (x-1)n = (x-1) Obviously, we can't add an infinite number of terms together, but we will use a finite number of terms to get an estimate for In(x) 1. In order to see how this algorithm works, fill in Table below forx 1.25 Iterative Algorithm for In(x) Initial Estimate0 k-1Estimate Estimate+(x-1)1/1 - k = 2 | Estimate-Estimate-(x-1)2 / 2 = k-3 Estimate Estimate(x- 1)3/3 4 | Estimate = Estimate Edw 4 = Note: In(1.25) = 0.2231. The algorithm provides a pretty accurate estimate after only four iterations for this particular number, x 1.25 2. Write a script file to estimate the natural log of a number which is greater than 0 and does not exceed 2 using a finite number of terms from the Taylor Series. Your program should first prompt the user for the number,x, and for the number of desired terms, N Your program should check and see if x is an invalid number; that is, x is less than or equal to 0 or greater than 2. Use a while loop for this! if the number is invalid, prompt the user to enter a new valid value for the number. The while loop is nice because it will continue to prompt the user until the user finally enters an acceptable value of x. Your program should then use a for loop (for k = 1:N) to calculate the estimate of the natural log using N terms. Remember: in MATLAB, natural log is log. Hint: Look at Table above. Each iteration, Estimate = Estimate + New Term. The equation for the New Term changes every iteration. It obviously depends on x. See if you can figure out how to relate the equation to k (the index variable for your loop) also .After the for loop, add an fprintf statement to display the estimate of the In(x) with 8 places behind the decimal point. 3. Test your program to make sure it doesn't accept invalid values for x. Try negative values, zero, and values above 2Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started