0% found this document useful (0 votes)
29 views4 pages

Experiment 5 2305903

The document demonstrates Newton's Forward and Backward Interpolation methods to estimate unknown function values. It includes coding examples to find f(0.5) and f(300) using both interpolation techniques, yielding results of 3.125 and 1148, respectively. The conclusion highlights the effectiveness of these methods in numerical approximation and function estimation.

Uploaded by

techxsumit1904
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)
29 views4 pages

Experiment 5 2305903

The document demonstrates Newton's Forward and Backward Interpolation methods to estimate unknown function values. It includes coding examples to find f(0.5) and f(300) using both interpolation techniques, yielding results of 3.125 and 1148, respectively. The conclusion highlights the effectiveness of these methods in numerical approximation and function estimation.

Uploaded by

techxsumit1904
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/ 4

EXPERIMENT 5

AIM : Demonstration of newton forward and backward interpolation

OBJECTIVE : To accurately estimate unknown function values using Newton’s


Forward and Backward Interpolation methods and demonstrate their effectiveness in
numerical analysis.

PROBLEM STATEMENT :
Find f(0.5) using Newton’s forward difference formula
x = [0 1 2 3 4];
y = [1 7 23 55 109];

CODING :
clc;
clear;
function y_interp = newton_forward_interpolation(x, y, x_interp)
if length(x) ~= length(y)
error('Lengths of x and y must be the same');
end
n = length(x);
f_diff = zeros(n, n);
f_diff(:, 1) = y;
for j = 2:n
for i = 1:n-j+1
f_diff(i, j) = f_diff(i+1, j-1) - f_diff(i, j-1);
end
end
h = x(2) - x(1);
p = (x_interp - x(1)) / h;
y_interp = y(1);
p_term = 1;
fact = 1;
for j = 2:n
p_term = p_term * (p - (j-2));
fact = fact * (j-1);
y_interp = y_interp + (p_term / fact) * f_diff(1, j);
end
end
x = [0 1 2 3 4];
y = [1 7 23 55 109];
x_interp = 0.5;
y_interp = newton_forward_interpolation(x, y, x_interp);
disp(['f(0.5) = ', num2str(y_interp)]);

OUTPUT :
f(0.5) = 3.125

PROBLEM STATEMENT :
Find f(300) using Newton’s backward difference formula

18
x = [50 100 150 200 250];
y = [618 724 805 906 1032];

CODING :
clc;
clear;
function y_interp = newton_backward_interpolation(x, y, x_interp)
if length(x) ~= length(y)
error('Lengths of x and y must be the same');
end
n = length(x);
f_diff = zeros(n, n);
f_diff(:, 1) = y;
for j = 2:n
for i = n:-1:j
f_diff(i, j) = f_diff(i, j-1) - f_diff(i-1, j-1);
end
end
h = x(2) - x(1);
p = (x_interp - x(n)) / h;
y_interp = y(n);
p_term = 1;
fact = 1;
for j = 2:n
p_term = p_term * (p + (j-2));
fact = fact * (j-1);
y_interp = y_interp + (p_term / fact) * f_diff(n, j);
end
end
x = [50 100 150 200 250];
y = [618 724 805 906 1032];
x_interp = 300;
y_interp = newton_backward_interpolation(x, y, x_interp);
disp(['f(300) = ', num2str(y_interp)]);

OUTPUT :
f(300) = 1148

PROBLEM STATEMENT :
Find f(300) using Newton’s forward difference formula
x = [50 100 150 200 250];
y = [618 724 805 906 1032];

CODING :
clc;
clear;
function y_interp = newton_forward_interpolation(x, y, x_interp)
if length(x) ~= length(y)
error('Lengths of x and y must be the same');
end

19
n = length(x);
f_diff = zeros(n, n);
f_diff(:, 1) = y;
for j = 2:n
for i = 1:n-j+1
f_diff(i, j) = f_diff(i+1, j-1) - f_diff(i, j-1);
end
end
h = x(2) - x(1);
p = (x_interp - x(1)) / h;
y_interp = y(1);
p_term = 1;
fact = 1;
for j = 2:n
p_term = p_term * (p - (j-2));
fact = fact * (j-1);
y_interp = y_interp + (p_term / fact) * f_diff(1, j);
end
end
x = [50 100 150 200 250];
y = [618 724 805 906 1032];
x_interp = 300;
y_interp = newton_forward_interpolation(x, y, x_interp);

disp(['f(300) = ', num2str(y_interp)]);

OUTPUT :
f(300) = 1148

PROBLEM STATEMENT :
Find f(0.5) using Newton’s backward difference formula
x = [0 1 2 3 4];
y = [1 7 23 55 109];

CODING :
clc;
clear;
function y_interp = newton_backward_interpolation(x, y, x_interp)
if length(x) ~= length(y)
error('Lengths of x and y must be the same');
end
n = length(x);
f_diff = zeros(n, n);
f_diff(:, 1) = y;
for j = 2:n
for i = n:-1:j
f_diff(i, j) = f_diff(i, j-1) - f_diff(i-1, j-1);
end
end
h = x(2) - x(1);

20
p = (x_interp - x(n)) / h;
y_interp = y(n);
p_term = 1;
fact = 1;
for j = 2:n
p_term = p_term * (p + (j-2));
fact = fact * (j-1);
y_interp = y_interp + (p_term / fact) * f_diff(n, j);
end
end
x = [0 1 2 3 4];
y = [1 7 23 55 109];
x_interp = 0.5;
y_interp = newton_backward_interpolation(x, y, x_interp);
disp(['f(0.5) = ', num2str(y_interp)]);

OUTPUT :
f(0.5) = 3.125

CONCLUSION :
Newton’s Forward and Backward Interpolation methods were successfully applied to
estimate function values from given data points. Forward interpolation was used for
points near the beginning, while backward interpolation was used for points near the
end. The results demonstrate the effectiveness of these methods in numerical
approximation and function estimation.

NAME : SUMIT MANDAL


ROLL : 2305903
SEC : CSE - 30

21

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy