Newton's forward difference table is incorrect for some Y values
이전 댓글 표시
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
Walter Roberson
2025년 10월 19일
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
2025년 10월 19일
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.

답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!