Part I-Lagrange Polynomials Theorem (Lagrange Polynomials] Let f(x) be continuous on the interval [a, b] and n times differentiable on the interval (a, b). If x_0, x_1, ... x_n are (n+1) distinct numbers in [a, b] then there exists a unique polynomial L_n of degree at most n with the property that f(x_n) = L_n(x_k), for each k = 0, 1, ..., n. Specifically, this polynomial is given by L_n(x) = f(x_0)L_n, 0(x) + ...+ f(x_n)L)n, m(x)= Sigma_ k = 0^n f(x_k)L_n, k(x), where L_n, k(x) = (x - x_0)(x - x_1) ... (x - x_k - 1)(x - x_k + 1)...(x - x_n)/(x_k - x_0) (x_k - x_1)...()x_k - x_k - 1)(x_k - x_k + 1)...(x_k - x_n) = Pi_i =0, i notequalto k^n (x - x_i)/(x_k - x_i). Furthermore, we have that the remainder term R_n(x) = f(x) - L_n(x) satisfies R_n(x) = f(x) - L_n(x) = f^(n + 1)(eta)/(n + 1)! (x - x_0)(x - x_1)...(x - x_n), (1) for some eta epsilon (a, b). Exercise 1. Write a Matlab function which will find a the Lagrange polynomial of degree 2 through three given points. Use your function which will find the Lagrange polynomial of degree 2 through the points (0, 2), (1, 3) and (3, -1).
function [ fx ] = langrangePolyOfDegree2( p1, p2, p3 )
fx1 = @(x)( p1(1,2)*(((x-p2(1,1))*(x-p3(1,1)))/((p1(1,1)-p2(1,1))*(p1(1,1)-p3(1,1)))) );
fx2 = @(x)( p2(1,2)*(((x-p1(1,1))*(x-p3(1,1)))/((p2(1,1)-p1(1,1))*(p2(1,1)-p3(1,1)))) );
fx3 = @(x)( p3(1,2)*(((x-p2(1,1))*(x-p1(1,1)))/((p3(1,1)-p2(1,1))*(p3(1,1)-p1(1,1)))) );
fx = @(x)( fx1(x) + fx2(x) + fx3(x) );
end