Use Lagrange interpolating polynomial method and cubic spline interpolation to evaluate the function f(x) at 100 equally spaced points in the interval [0,5].

17 次查看(过去 30 天)
X1 = [0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5];
Y1 = [0 0.247466462 0.881373587 1.550157957 2.094712547 2.532068064 2.893443986 3.200334942 3.466711038 3.70191108 3.912422766];
xx = linspace(0,5,100);
yy = lagrange_self(X1,Y1,xx);
s = spline(X1,Y1,xx);
plot(X1,Y1,'o',xx,yy,'.',xx,s,'*')
legend('ORIGINAL','LAGRANGE-CUBIC','CUBIC-SPLINE')
Error_lagrange = sum(((yy-7*xx).^2).^0.5)
Error_spline = sum(((s-7*xx).^2).^0.5)
function v = lagrange_self(x,y,u)
n = 4;
v = zeros(size(u));
for k = 1:n
w = ones(size(u));
for j = [1:k-1 k+1:n]
w = (u-x(j))./(x(k)-x(j)).*w;
end
v = v+w*y(k)
end
end
  1 个评论
Kutlu Yigitturk
Kutlu Yigitturk 2020-12-25
Use Lagrange interpolating polynomial method and cubic spline interpolation to evaluate the function f(x) at 100 equally spaced points in the interval [0,5]. Use cubic polynomial for Lagrange’s method as well. The points to be used in interpolations should include first and last point (0 and 5), other two points should be chosen such that those points would represent significant change in f(x). Show the plots for Lagrange’s method, cubic spline and the given data in one graph. Discuss which method is better.
Calculate the total error for both methods by using the following formula. Here yi is the given y value for xi , and f(xi) is the value of the interpolating function at point xi .
I WROTE THIS CODE, BUT I JUST WANT TO MAKE SURE IT'S WORKING OR NOT. CAN YOU PLEASE CHECK MY CODE, ACCORDING TO THE MY PARAGRAPH. I WILL BE WAITING YOUR HELP.
SINCERELY,
KUTLU YIGITTURK.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by