Newton's forward difference table is incorrect for some Y values
Show older comments
Hi all,
I am doing an assessment item that requires us to construct the Newton's forward difference table for the function values Y = [y0, y1, ... yn]. The activity is on MATLAB Grader.
I keep getting the same error: "code is incorrect for some values of Y." I think I have the correct code for the table itself but I can't figure out how to make it correct for every value.
Here is my code:
function T = forward_differences(Y)
if ~isnumeric(Y) || ~isvector(Y) % this is my attempt to fix the error
error('Input must be a numeric vector.');
end
n = length(Y);
T = zeros(n,n);
T(:,1) = Y(:);
for j = 2:n
for i = 1:n-j+1
T(i,j) = T(i+1,j-1) - T(i,j-1);
end
end
end
Here is an example of output:
Y = [2 4 9]
T = forward_differences(Y)
Thanks in advance!
3 Comments
Walter Roberson
on 19 Oct 2025
I wonder if you need the transpose of that T -- so the first row represents the initial values, the second row represents the first differences, and so on.
Sam Chak
on 19 Oct 2025
Hi @Pia
The entries in Newton's forward difference table are computed as shown. While your computations appear to be correct, please verify whether the question requires you to include the column for "x" in the table as well. Occasionally, the warning messages in some grading questions are automated based on reasonable assumptions, regardless of the type of error.

Answers (0)
Categories
Find more on Noncentral t Distribution in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!