Deliverable: Submit a Live script titled vorksheet6.ml via CatCourses under Assignments Divide this file into sections, one f

Deliverable: Submit a Live script titled vorksheet6.ml via CatCourses under Assignments Divide this file into sections, one for each of the following questions, plus an extra (final) section containing all the function definitions. Document each function definition to explain the input and output arguments. Also document key portions of the algorithm to make it clear you understand how your code works. 1. The Lagrange interpolation formula, 1-0 -0 evaluates y p(z), where is given and p įs the (unique) degreen polynomial that interpolates n + 1 given coor- dinate pairs, (10:30), (11 M), . . . , (Fn, yn). (“Interpolates” means intersects, İ.е., y-p(z.) fr i = 0, 1, . . . , n.) (a) Implement this as a Matlab function with the signature function y -linterp(X, Y, x) (X and Y are arrays containing ro,…, In and yo, …, Vn, resp.) You may not use any of Matlab’s poly nomial routines (like polyfit or interp1) nor the Symbolic Math Toolbox. Test your code by 1. picking your favorite polynomial p of degree five, 2. populating X with six distinct numbers, 3. setting Y to be p evaluated at the corresponding entries of X, using polyval, 4. picking x to be a number besides those in X 5. comparing p) with linterp(X, Y, x) For example, implement H1 by p (x) polyval([1 0 0 0 0 -1], x): (b) Based on the formula, for what inputs (X, Y, wl Lagrange interpolation fail (not return a real number)? Modify your linterp documentation to mention this (input) requirement. c) Extend your code to allow x to be an array, so that y is an array of the same dimensions, each entry being the Lagrange interpolation formula evaluated at the corresponding entry of x. Reusing from Part (a) the polynomial function p and the arrays X and Y, run the following commands x = linspace (min(X)-1, max(X)+1, 100); plot(x, p(x) ko: ‘, x, linterp(X, Y, x), ‘rx:); The red ×s should coincide with the black 08. Show transcribed image text Deliverable: Submit a Live script titled vorksheet6.ml via CatCourses under Assignments Divide this file into sections, one for each of the following questions, plus an extra (final) section containing all the function definitions. Document each function definition to explain the input and output arguments. Also document key portions of the algorithm to make it clear you understand how your code works. 1. The Lagrange interpolation formula, 1-0 -0 evaluates y p(z), where is given and p įs the (unique) degreen polynomial that interpolates n + 1 given coor- dinate pairs, (10:30), (11 M), . . . , (Fn, yn). (“Interpolates” means intersects, İ.е., y-p(z.) fr i = 0, 1, . . . , n.) (a) Implement this as a Matlab function with the signature function y -linterp(X, Y, x) (X and Y are arrays containing ro,…, In and yo, …, Vn, resp.) You may not use any of Matlab’s poly nomial routines (like polyfit or interp1) nor the Symbolic Math Toolbox. Test your code by 1. picking your favorite polynomial p of degree five, 2. populating X with six distinct numbers, 3. setting Y to be p evaluated at the corresponding entries of X, using polyval, 4. picking x to be a number besides those in X 5. comparing p) with linterp(X, Y, x) For example, implement H1 by p (x) polyval([1 0 0 0 0 -1], x): (b) Based on the formula, for what inputs (X, Y, wl Lagrange interpolation fail (not return a real number)? Modify your linterp documentation to mention this (input) requirement. c) Extend your code to allow x to be an array, so that y is an array of the same dimensions, each entry being the Lagrange interpolation formula evaluated at the corresponding entry of x. Reusing from Part (a) the polynomial function p and the arrays X and Y, run the following commands x = linspace (min(X)-1, max(X)+1, 100); plot(x, p(x) ko: ‘, x, linterp(X, Y, x), ‘rx:); The red ×s should coincide with the black 08.