Problem, \"3 ) [20 pts] The code below performs an interpolation using linear La
ID: 3282591 • Letter: P
Question
Problem, "3 ) [20 pts] The code below performs an interpolation using linear Lagrange polynomial. However, the program contains errors in the highlighted lines. Debug the program by crossing out the incorrect parts and writing the correct code next to them. % estimating x-10 %raw x and y data xr - 10; x=[4 8 11 14]; y-[4 9 12 16); xo-x(3); xì-x(4); xx-[x0, xiledrT %pick 2 data points % Order of polynomial % compute L coefficients for k=1:N+1 for j 1:N+ ifj-k num(j) = XX(j)-xm denG)-y(k)- yy0): else num()- end LL(k) = sum(num) Xsumoderk end end LIO-LL(1); L11 LL(2) % assign coefficients % compute estimate at xrExplanation / Answer
xr=10;% estimating x=10
x=[4 8 11 14];% raw x and y data
y=[4 9 12 16];
x0=x(2);x1=x(3);xx=[x0,x1]; % pick 2 data points which can best estimate the interpolation
y0=y(2);y1=y(3);yy=[y0,y1];
N=1;% we are using only 2 data points to estimate the value of x at 10 so order of polynomial is 1
for k=1:N+1 %computing L coefficients
for j=1:N+1
if j~=k
num(j)=xr-xx(j);
den(j)=yy(k)-yy(j);
else
num(j)=1;
den(j)=1;
end
LL(k)=prod(num)./prod(den);
end
end
L10=LL(1);% assign coefficients
L11=LL(2);
P=y0*L10+y1*L11 % lagrange polynomial general form to estimate at xr
output:
P=11
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.