代写 matlab MACM 316 – Computing Assignment 1

MACM 316 – Computing Assignment 1
Due Date: Monday January 20 at 11:00pm.
You must upload one .pdf file that contains the following: Page 1 is your report (should fit all discussions, data and figures on a single page) and Page 2 is a listing of your code. The assignment is due at 11:00pm. The actual due time in Crowdmark is 11:05pm and if Crowdmark indicates that you submitted late, you will be given 0 on the assignment. Your TA will email you a Crowdmark link that will allow you to upload your completed assignment.
􏰀 Please read the Guidelines for Assignments first.
􏰀 Acknowledge any collaborations or assistance from colleagues/TAs/instructor.
􏰀 If you have any questions about Matlab or aspects of this assignment, then you are strongly encouraged to attend tutorials and drop-in workshops.
Computing Assignment – Floating Point Arithmetic
This assignment is a more extensive investigation of the rounding error example studied with the Matlab code roundex.m posted on Canvas. The polynomial function (x − a)n with a any real number and n a positive integer can be written in expanded form as
n 􏰅n 􏰃 n 􏰄 n − k k n 􏰃 n 􏰄 n − 1 􏰃 n 􏰄 n − 2 2 􏰃 n 􏰄 n − 3 3 (x−a) = k x (−a) =x − 1 x a+ 2 x a − 3 x a +…+
k=0
where 􏰁n􏰂 = n! are binomial coefficients.
1. Plot f(x) = (x − 2)n for n = 1,2,3,4,5,6 on the domain x ∈ [0,4], using the factored (unexpanded) form. Combine your plots together on the same axes, and use different colors and line styles to distinguish between the six curves. Choose an appropriate y-axis scale that ensures important features of the functions are visible. Consider this your “exact result”.
2. Write a Matlab function that computes the polynomial in expanded form. Your function should have three input parameters (a, n and x) and return a single output argument (the computed f(x)). You can make use of Matlab’s nchoosek to compute binomial coefficients. Test your code completely, making sure that it is able to exit gracefully with a suitable error/warning message for any value of the input arguments that would generate an invalid result.
3. Produce six plots of f(x) near x = 2, with a series of successively smaller x-axis scales on intervals x ∈ [2 − δ, 2 + δ] for δ = 0.5, 0.1, 0.05, 0.025, 0.01, 0.005. In your report, show only the plots for δ = 0.5, 0.05, 0.005 with 2 selected values of n (for a total of 6 plots) – choose the two values of n that you think most clearly illustrate your results! Discuss your plotted results for the various n and δ values, taking into account the following:
(a) Identify the smallest value of the exponent n for which the expanded polynomial differs from the factored form (the “exact” plot).
(b) Describe what you observe for even larger values of n.
(c) Explain briefly why performing computations in floating point arithmetic leads to the results you observe.
􏰃 n 􏰄 n n (−a) ,
k (n−k)! k!
1