Create Newton divided difference table using one looping

Hi, I was asked to compute the Newton divided difference table using at most one looping. My teacher didn't say if more loops within a single loop are allowable. So is it possible to do that? Actually I have no problem writing the code using nested loop:
for j=2:n
for k=j:n
D(k,j)=(D(k,j-1)-D(k-1,j-1))/(x(k)-x(k-j+1));
end
end
Any help is much appreciated, thanks!

답변 (2개)

Jan
Jan 2013년 2월 27일
편집: Jan 2013년 2월 27일
What happens, if you move the loop counter into the formula?
for j=2:n
D(j:n,j)=(D(j:n,j-1)-D(j-1:n-1,j-1)) ./ (x(j:n)-x(1:n-j+1));
end

댓글 수: 1

Thanks a lot but it doesn't work for me. Can you elaborate a little bit on how to move the loop into the formula?

댓글을 달려면 로그인하십시오.

Long Wu
Long Wu 2014년 4월 15일

0 개 추천

The solution suggested above is on right direction,
but need a little bit modification :
D(j:m,j)=(D(j:m, j-1)-D(j-1:m-1, j-1))./((x(j:m)-x(1:m-j+1)))';
As the front part is column vector , later part is row vector.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

Le
2013년 2월 27일

답변:

2014년 4월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by