The variable appears to change size in every loop iteration, I have no idea how to fix. I get this for divDIF Line 13 and a line 21.
조회 수: 11 (최근 30일)
이전 댓글 표시
function Yint = NewtonsINT(x,y,Xint)
% NewtonsINT fits a Newtons polynomial to a set of given points and
% uses the polynomial to determines the interpolated value of a point.
% Input variables:
% x A vector with the x coordinates of the given points.
% y A vector with the y coordinates of the given points.
% Xint The x coordinate of the point to be interpolated.
% Output variable:
% Yint The interpolated value of Xint.
n = length (x);
a(1) = y(1);
for i = 1:n - 1
divDIF(i,l)=(y(i+l)-y(i))/(x(i+ 1)-x(i));
end
for j = 2 :n - 1
for i = l:n - j
divDIF(i,j)=(divDIF(i+l,j-l)-divDIF(i,j-1))/(x(j+i)-x(i));
end
end
for j = 2 :n
a(j) = divDIF(l,j - 1);
end
Yint = a(1);
xn = 1;
for k = 2:n xn = xn*(Xint - x (k - 1));
Yint = Yint + a (k) *xn;
end
댓글 수: 0
답변 (1개)
Ameer Hamza
2018년 6월 26일
편집: Ameer Hamza
2018년 6월 26일
This is not an error, this is a warning which mlint produce to increase the speed and efficiency of your code. It is better to pre-allocate variable's memory to increase speed. For more details, see here: https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html. However, this warning should not stop the code from execution. The code should work as expected, although slower then pre-allocation. The actual error which I can see in your code is that the variable l is not defined. You are using it at several places of your code but its value is not assigned anywhere. This will be actually causing an error.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!