Code covered by the BSD License  

Highlights from
Numerical Methods Using MATLAB, 3e

image thumbnail

Numerical Methods Using MATLAB, 3e

by

 

20 Aug 2002 (Updated )

Companion Software

[A,df]=diffnew(X,Y)
function [A,df]=diffnew(X,Y)

%Input   - X is the 1xn abscissa vector
%        - Y is the 1xn ordinate vector
%Output  - A is the 1xn vector containing the coefficients of the Nth
%          degree Newton polynomial
%        - df is the approximate derivative

% NUMERICAL METHODS: MATLAB Programs
%(c) 1999 by John H. Mathews and Kurtis D. Fink
%To accompany the textbook:
%NUMERICAL METHODS Using MATLAB,
%by John H. Mathews and Kurtis D. Fink
%ISBN 0-13-270042-5, (c) 1999
%PRENTICE HALL, INC.
%Upper Saddle River, NJ 07458

A=Y;
N=length(X);

for j=2:N
   for k=N:-1:j
      A(k)=(A(k)-A(k-1))/(X(k)-X(k-j+1));
   end
end

x0=X(1);
df=A(2);
prod=1;
n1=length(A)-1;

for k=2:n1
   prod=prod*(x0-X(k));
   df=df+prod*A(k+1);
end

Contact us