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.

17 vues (au cours des 30 derniers jours)
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

Réponses (1)

Ameer Hamza
Ameer Hamza le 26 Juin 2018
Modifié(e) : Ameer Hamza le 26 Juin 2018
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.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by