0

I know this type of question have been asked plenty of times before, but I cannot understand the problem with my code. Also I am absolute beginner in Octave.

function Z=nat_spline(n, T, Y)
  for i=0:n-1
    H(i) = T(i+1) - T(i);
    B(i) = 6*(Y(i+1) - Y(i))/H(i);
  end
  U(1) = 2*(H(0)+H(1));
  V(1) = B(1) - B(0);
  for i=2:n-1
    U(i) = 2 * (H(i) + H(i-1)) - ( (H(i-1))^2 / U(i-1) );
    V(i) = B(i) - B(i-1) - H(i-1)*V(i-1)/U(i-1);
  end
  Z(n) = 0
  for i=n-1:1
    Z(i) = (V(i)-H(i)*Z(i+1))/U(i);
  end
  Z(0) = 0;
end

Its a short code, so I guess it would be easy to spot any mistake. Thanks a lot for any helps.

user44273
  • 752
  • 2
  • 7
  • 14
  • possible duplicate of [Subscript indices must either be real positive integers or logicals, generic solution](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) – Dennis Jaheruddin Jan 14 '14 at 14:47

2 Answers2

3

index of array start with 1 in matlab :) your H(i) and B(i) will be H(0) B(0) in the first iteration of the loop and that will give you an error so for i=1:n

Cici
  • 1,407
  • 3
  • 13
  • 31
0

Well, the title tells it: if not logicals. subscripts must be strictly positive integer values. Things like H(0) or Z(0) won't work, because strictly positive integer values begin with 1.