Newton's forward difference table is incorrect for some Y values
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 19 Okt. 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
am 19 Okt. 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.

Antworten (0)
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!