Question: Problem. Use the following pseudocode to plot the Lagrange polynomial for f(x) = 3e-z + 2 sin(x) on [0.3] through 4 points (i,f(i),-0.1.2.3. Also plot

 Problem. Use the following pseudocode to plot the Lagrange polynomial for

Problem. Use the following pseudocode to plot the Lagrange polynomial for f(x) = 3e-z + 2 sin(x) on [0.3] through 4 points (i,f(i),-0.1.2.3. Also plot the points and f on the same figure. Explain steps by commenting on them Algorithm Lagrange-Polynomial-Interpolation Input: f(z) = 3e-z + 2 sin(x), X = [0, 1, 2, 3], Y = [f(0), f (1)/(2), f Output: Lagrange polynomial P, Graphs of f and P3 through (X(i), Y(i), i = 0-3 set n = length of X: L is a zero vector of length n; for i 1 to r (i) 1: for j = 1 to n if (j i) (i) = L(i) * (x-x(j))/(x(i)-x(j)); end if end for P = P + Y(i) * L(i); end for print P plot P in blue plot f in red plot (x(i), Y(i)), i = 0, . . . , 3 in red Useful commands: (See Matlab 0) plot(X, Y Or') To plot points in red and f on [0, 3] in red: hold on fplot(f, [0,3],'r') % define f before this . To define P3 as a "symbolic" function of the "variable" x, use: syms L = sym(zeros(size(X))) Then before the for loop write L as follows: Problem. Use the following pseudocode to plot the Lagrange polynomial for f(x) = 3e-z + 2 sin(x) on [0.3] through 4 points (i,f(i),-0.1.2.3. Also plot the points and f on the same figure. Explain steps by commenting on them Algorithm Lagrange-Polynomial-Interpolation Input: f(z) = 3e-z + 2 sin(x), X = [0, 1, 2, 3], Y = [f(0), f (1)/(2), f Output: Lagrange polynomial P, Graphs of f and P3 through (X(i), Y(i), i = 0-3 set n = length of X: L is a zero vector of length n; for i 1 to r (i) 1: for j = 1 to n if (j i) (i) = L(i) * (x-x(j))/(x(i)-x(j)); end if end for P = P + Y(i) * L(i); end for print P plot P in blue plot f in red plot (x(i), Y(i)), i = 0, . . . , 3 in red Useful commands: (See Matlab 0) plot(X, Y Or') To plot points in red and f on [0, 3] in red: hold on fplot(f, [0,3],'r') % define f before this . To define P3 as a "symbolic" function of the "variable" x, use: syms L = sym(zeros(size(X))) Then before the for loop write L as follows

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!