Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions