The Newton's backward and forward interpolation formulas are given by:
The value of y(x) at x=15501 and 15502 is computed using the MATLAB coding as given below:
close all,
clear all,
clc,
x = [15500, 15510, 15520, 15530, 15540];
y = [124.4990, 124.5392, 124.5793, 124.6194, 124.6595];
Delta_y_1 = [];
Delta_y_2 = [];
Delta_y_3 = [];
Delta_y_4 = [];
temp = y;
for r=2:length(temp)
Delta_y_1(r-1) = temp(r) - temp(r-1);
end
temp = Delta_y_1;
for r=2:length(temp)
Delta_y_2(r-1) = temp(r) - temp(r-1);
end
temp = Delta_y_2;
for r=2:length(temp)
Delta_y_3(r-1) = temp(r) - temp(r-1);
end
Delta_y_4 = Delta_y_3(2) - Delta_y_3(1);
fprintf('\n\nNewton Difference Taqble\n');
fprintf(' x y(x) DeltaY DeltaY^2 DeltaY^3 DeltaY^4');
for r=1:length(x)
if(r==1), fprintf('\n%8d%10.4f',x(r),y(r)); end
if(r==2),
fprintf('\n%8d%10.4f%10.4f',x(r),y(r),Delta_y_1(r-1));
end
if(r==3),
fprintf('\n%8d%10.4f%10.4f%10.4f',x(r),y(r),Delta_y_1(r-1),Delta_y_2(r-2));
end
if(r==4),
fprintf('\n%8d%10.4f%10.4f%10.4f%10.2f',x(r),y(r),Delta_y_1(r-1),Delta_y_2(r-2),Delta_y_3(r-3));
end
if(r==5),
fprintf('\n%8d%10.4f%10.4f%10.4f%10.2f%10.4f',x(r),y(r),Delta_y_1(r-1),Delta_y_2(r-2),Delta_y_3(r-3),Delta_y_4);
end
end
fprintf('\n\nNewton Forward Difference Interpolation Computation');
XVal=15501;
fprintf('\n\nGiven Input X = %d, Therefore y(%d) = ?',XVal,XVal);
h = x(2)-x(1);
fprintf('\nh = x(1) - x(0) = %d - %d = %d',x(2),x(1),h);
p = (XVal - x(1))/h;
fprintf('\np = (X - x(0)/h = (%d - %d)/%d = %.3f',XVal,x(1),h,p);
fprintf('\n\nNewton Forward Diff. Interpolation Formula is:');
fprintf('\ny(x) = y + p.y + p(p-1)DeltaY^2/2! + p(p-1)(p-2)DeltaY^3/3! + p(p-1)(p-2)(p-3)DeltaY^4/4!');
fprintf('\n\n');
YVal = y(1) + p*Delta_y_1(1) + ((p*(p-1)*Delta_y_2(1))/2) + ((p*(p-1)*(p-2)*Delta_y_3(1))/6) + ((p*(p-1)*(p-2)*(p-3)*Delta_y_4)/24);
fprintf('Equating all values in above equation, we get y(%d) = %f\n',XVal,YVal);
XVal=15502;
p = (XVal - x(1))/h;
YVal = y(1) + p*Delta_y_1(1) + ((p*(p-1)*Delta_y_2(1))/2) + ((p*(p-1)*(p-2)*Delta_y_3(1))/6) + ((p*(p-1)*(p-2)*(p-3)*Delta_y_4)/24);
fprintf('Equating all values in above equation, we get y(%d) = %f\n',XVal,YVal);
XVal=15501;
fprintf('\n\n\nNewton Backward Difference Interpolation Computation');
fprintf('\n\nGiven Input X = %d, Therefore y(%d) = ?',XVal,XVal);
h = x(2)-x(1);
fprintf('\nh = x(1) - x(0) = %d - %d = %d',x(2),x(1),h);
p = (XVal - x(5))/h;
fprintf('\np = (X - x(n)/h = (%d - %d)/%d = %.3f',XVal,x(5),h,p);
fprintf('\n\nNewton Backward Diff. Interpolation Formula is:');
fprintf('\ny(x) = yn + p.yn + p(p+1)DeltaYn^2/2! + p(p+1)(p+2)DeltaYn^3/3! + p(p+1)(p+2)(p+3)DeltaYn^4/4!');
YVal = y(5) + p*Delta_y_1(4) + ((p*(p+1)*Delta_y_2(3))/2) + ((p*(p+1)*(p+2)*Delta_y_3(2))/6) + ((p*(p+1)*(p+2)*(p+3)*Delta_y_4)/24);
fprintf('\nEquating all values in above equation, we get y(%d) = %f\n',XVal,YVal);
XVal=15502;
p = (XVal - x(5))/h;
YVal = y(5) + p*Delta_y_1(4) + ((p*(p+1)*Delta_y_2(3))/2) + ((p*(p+1)*(p+2)*Delta_y_3(2))/6) + ((p*(p+1)*(p+2)*(p+3)*Delta_y_4)/24);
fprintf('Equating all values in above equation, we get y(%d) = %f\n',XVal,YVal);
Comments
Leave a comment