Question: Code the following using C++ language in Matlab: For this exercise, you are asked to implement the Horners algorithm on the evaluation of y=x-sin(x). Your

Code the following using C++ language in Matlab:

For this exercise, you are asked to implement the Horners algorithm on the evaluation of y=x-sin(x). Your main code should request the user to input two numbers, 1. the maximum power in the series expansion of sin(x), and 2. the value of x. These two parameters are then passed as inputs to your Horner function, and the output of your Horner function should be the sum. You are welcome to check lecture note sample implementations, but there are a few updated requirements, 1. Your main code should ask the user to enter only an odd number for max power. If someone enters an even number, your Horner function should write something like must input an odd power! and then return nan (not a number) as the summation output. 2. Remember that my Horner code for the polynomial sums all degrees (even and odd), your problem here only deals with odd degrees, which means indexing must change twice as fast in the loop. 3. You should try to debug your code carefully in the loop that does the calculations within the function. I suggest that you do a print statement of the index i, the normalization factor (e.g., 42, 20, etc.), enter x = 1.0, and do this with pen and paper and see if your summation is as expected from the lecture notes. 4. Remember the final term x^3/6 should multiplied last, and outside the loop since it does not share the same pattern (repeated pattern) as other powers. Once you are happy with the performance of your function, please modify the main code (that calls the function) and print out the difference between the expected value using Matlab built-in function (x-sin(x)) and your function output. Use %e format to print the difference. [I suggest you try max power n = 9, 19, 29 and x=10.0 and see what happens. Then enter max power = 9 and x = 1.0, what happens in this case? Why?]

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!