In the code below I'm trying to produce the following summation notation with the answers expected being 1,-2,1 (second derivative,central finite difference coefficient)
However when I run my code the answer for S = NaN, and I'm a bit lost as to where I've gone wrong.
n = 2;
k = n/2;
for j=0:n
S = 0;
for i=0:n
if (i~=j)
end
sum=0;
for m=0:n
if (m~=j) && (m~=i)
end
prod=1.0;
for l=0:n
if (l~=j) && (l~=i) && (l~=m)
prod=prod*(n/2-l)/(j-l);
end
end
prod=prod*1/(j-m);
sum=sum+prod;
end
S=S*(1/(j-i))*sum;
end
end
Any help much appreciated, thanks in advance.
3 Comments
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/719210-summation-subroutine-giving-result-as-nan-not-a-number#comment_1268015
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/719210-summation-subroutine-giving-result-as-nan-not-a-number#comment_1268015
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/719210-summation-subroutine-giving-result-as-nan-not-a-number#comment_1268170
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/719210-summation-subroutine-giving-result-as-nan-not-a-number#comment_1268170
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/719210-summation-subroutine-giving-result-as-nan-not-a-number#comment_1271080
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/719210-summation-subroutine-giving-result-as-nan-not-a-number#comment_1271080
Sign in to comment.