Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can someone give me a simple example in how to use this code to plot a Lagrange

ID: 3605926 • Letter: C

Question

can someone give me a simple example in how to use this code to plot a Lagrange polynomial?
thank you!

function y=lagrange (x,point, pointy) LAGRANGE approx a point-defined function using the Lagrange polynomial interpolation LAGRANGE (X, POINTX, POINTY) approx the function definited by the pointa: Pl- (POINTX (1), POINTY (1)), P2- (POINTX (2), POINTY (2))PN (POINTX (N), POTNTY (N)) and calculate it in each elements of x 0nsize (pointx,2): T-ones tn,size (x, 2)) 14 for 1:n if (13) E- end 18- 9 end 20-O; 21-B for i=1:n end C4

Explanation / Answer

function y=mylagrange (x,pointx,pointy)

ndp=x;

y=1

for k=1:ndp

if k~=pointx

y=y*(x-x(pointx))/pointy-x

(x-x(pn))/(x(p1)-x(p2));

end

--------------------------

if true

x=[1 3 4 5 8]

n=length(x)

for j=1:n

for x=x(1:n)

mylagrange(x,pointx,pointy)

plot(x,sum(mylagrange(x,pointx,pointy)

hold on

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote