For correction: Newton's Divided Difference method polynomial (nested form)
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm taking a MSc course in Applied Numerical Analysis and the programming language/software for the class is Matlab which is a fairly unfamiliar territory to me and I have limited time to master all of its syntax and semantics.
We were asked to derive a 6th order polynomial p(x) (where n =6) that is approximately equal to the function f(x) = log10(x) and subsequently solve for f(x) when the value of x = 1.43 using the Newton's Divided difference as follows:
p(x) = a0 + (x-x0)[a1 + (x-x1)[a2 + (x-x2)[a3 + (x-x3)[a4 + % (x-x4)[a5]]]]]
Here's the best I could come up with for now:
NewtonsDiffMtd_150517_.m (Assignment)
clear
clc
close all
% Given Data points are:
X = [1.2 1.3 1.4 1.5 1.6 1.7]; % Values for X
Y = log10(X); % Y = f(X) = log(X)
x_i = 1.43; % value of interest to be
%interpolated
% First, we find the Newton Coefficient, a. That is,
%function a = newtonCoeff(X,Y)
n = length(X(:,1)); % no. of X data points to be read
a = Y; % Stores the value of Y data point
% Y data points in the array a
for k = 2:n % For loop iterates over each elmt
a(k:n) = (a(k:n) - a(k-1))./(X(k:n)- X(k-1));
end
% Next, we program Newton Method Polynomial:
% Given by: p(x) = a0 + (x-x0)[a1 + (x-x1)[a2 + (x-x2)[a3 + (x-x3)[a4 +
% (x-x4)[a5]]]]]
% NOTE: This is achieved by deploying a backward recursion:
p = a(n);
for k = 1:n-1;
p = a(n-k) + (x_i - X(n-k))*p;
end
% Display the results:
disp(['Values of p: ' num2str(p)]);
I used an algorithm provided in a book: "Numerical Methods for Engineering with MATLAB" by Jaan Kiusalaas.
Please, I would be glad if you could help me correct this so that the each values of x is displayed and that the value of interest (x_i) is used in the final result of p(x).
Thank you in advance.
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!