0% found this document useful (0 votes)
25 views1 page

X (1 2 3 4 5 6 7 8) Y (0 1 0 1 0 1 0 1) (P, R, S) Lagrangepoly (X, Y) XX 0.5: 0.01: 8.5 Plot (XX, Polyval (P, XX), X, Y,, R, S,, XX, Spline (X, Y, XX) ,) Grid Axis ( (0.5 8.5 - 5 5) )

This document uses Matlab code to generate a Lagrange polynomial interpolation of data points (X,Y) and plots the polynomial, data points, and spline interpolation on the same graph for comparison. It generates the Lagrange polynomial coefficients P, residuals R, S from the data and evaluates the polynomial for values xx from 0.5 to 8.5 in 0.01 increments to plot the interpolation as a solid line along with the original data points as red circles, residuals as blue dots, and spline interpolation as a dashed green line, on a graph with x-axis from 0.5 to 8.5 and y-axis from -5 to 5 with gridlines.

Uploaded by

okokok1226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

X (1 2 3 4 5 6 7 8) Y (0 1 0 1 0 1 0 1) (P, R, S) Lagrangepoly (X, Y) XX 0.5: 0.01: 8.5 Plot (XX, Polyval (P, XX), X, Y,, R, S,, XX, Spline (X, Y, XX) ,) Grid Axis ( (0.5 8.5 - 5 5) )

This document uses Matlab code to generate a Lagrange polynomial interpolation of data points (X,Y) and plots the polynomial, data points, and spline interpolation on the same graph for comparison. It generates the Lagrange polynomial coefficients P, residuals R, S from the data and evaluates the polynomial for values xx from 0.5 to 8.5 in 0.01 increments to plot the interpolation as a solid line along with the original data points as red circles, residuals as blue dots, and spline interpolation as a dashed green line, on a graph with x-axis from 0.5 to 8.5 and y-axis from -5 to 5 with gridlines.

Uploaded by

okokok1226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

X = [1 2 3 4 5 6 7 8];

Y = [0 1 0 1 0 1 0 1];
[P,R,S] = lagrangepoly(X,Y);

xx = 0.5 : 0.01 : 8.5;


plot(xx,polyval(P,xx),X,Y,'or',R,S,'.b',xx,spline(X,Y,xx),'--g')
grid
axis([0.5 8.5 -5 5])

You might also like