I have a having a a matrix index bounds in matlab
Posted
by Ben Fossen
on Stack Overflow
See other posts from Stack Overflow
or by Ben Fossen
Published on 2010-03-23T02:41:18Z
Indexed on
2010/03/23
2:51 UTC
Read the original article
Hit count: 385
I keep getting the error( this is in Matlab) Attempted to access r(0,0); index must be a positive integer or logical.
Error in ==> Romberg at 15
I ran it with Romberg(1.3, 2.19,8)
I think the problem is the statment is not logical because I made it positive and still got the same error. anyone got some ideas of what i could do?
function Romberg(a, b, n)
h = b - a;
r = zeros(n,n);
for i = 1:n
h = h/2;
sum1 = 0;
for k = 1:2:2^(i)
sum1 = sum1 + f(a + k*h);
end
r(i,0) = (1/2)*r(i-1,0) + (sum1)*h;
for j = 1:i
r(i,j) = r(i,j-1) + (r(i,j-1) - r(i-1,j-1))/((4^j) - 1);
end
end
disp(r);
end
function f_of_x = f(x)
f_of_x = sin(x)/x;
end
© Stack Overflow or respective owner