function newton_divided_difference( f, min_x, max_x, n )
%UNTITLED Use Newton difference quotient method to interpolate
% f Is the original function ,min_x max_x The interval is defined ,n Is polynomial degree
% step 1: seek x,f,f[1],f[2]...f[n] x = min_x : (max_x-min_x)/n : max_x; for i = 1:1:n+1 y(i) = f(x(i)); end a=[x',y']; for i = 1:1:n for j = 1:1:(n-i+1) a(j,i+2) = (a(j+1,i+1)-a(j,i+1))/(a(j+i,1)-a(j,1)); end end % step 2: Draw the original function image figure(1); STEP = 0.001; x = min_x : STEP : max_x; for i = 1:1:((max_x-min_x)/STEP+1) y_1(i) = f(x(i)); end plot(x,y_1,'r') % step 3: Draw an interpolation function image hold on for i = 1:1:((max_x-min_x)/STEP+1) y_2(i) = a(1,n+2); for j = n:-1:1 y_2(i) = y_2(i) * (x(i) - a(j,1)) + a(1,j+1); end end plot(x,y_2,'b') hold off % step 4: Draw error image figure(2); y_error = y_1 - y_2; plot(x,y_error)
end
How can I use the Newton interpolation polynomial with Chebyshev as the zero point ?
版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/12/20211207164906761S.html