George Peppa
George Peppa

Reputation: 253

"Invalid Index" error in Scilab

I'm using the following code:

for t = linspace(0,2,500)   

   x(t) = 1+ t^2;   
   y(t) = 2*t;  
   r(t) = sqrt((x(t))^2+(y(t))^2);  

   radius = 1.6

   if r(t) > 0.999*radius & r(t) < 1.001*radius then
       solucion = t;

   end
end;

disp(solucion, "the solution is:")

Which works fine with t > 1 and different radius values.

But I get error 21: Invalid index when t takes values between 0 and 1.

I need to work with those values as well. How do I handle this?

Upvotes: 1

Views: 19148

Answers (1)

Christopher Creutzig
Christopher Creutzig

Reputation: 8774

Just so this shows up as answered in the overview:

Array indices in Scilab and MATLAB have to be positive integers (or logicals, but that is definitely not what you want here). If you need your t to vary over a range starting at 0, always write x(t+1). If you need non- integer values, still iterate over integers and compute the non-integral values from the loop index.

Upvotes: 1

Related Questions