"Invalid Index" Scilab 中的错误
"Invalid Index" error in Scilab
我正在使用以下代码:
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:")
在 t
> 1 和不同的半径值下效果很好。
但是当 t
取值介于 0 和 1 之间时,我得到 error 21: Invalid index
。
我也需要使用这些值。我该如何处理?
正如概述中所回答的那样:
Scilab 和 MATLAB 中的数组索引必须是正整数(或逻辑值,但这绝对不是您想要的)。如果您需要 t
在从 0 开始的范围内变化,请始终写 x(t+1)
。如果您需要非整数值,仍然迭代整数并从循环索引计算非整数值。
我正在使用以下代码:
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:")
在 t
> 1 和不同的半径值下效果很好。
但是当 t
取值介于 0 和 1 之间时,我得到 error 21: Invalid index
。
我也需要使用这些值。我该如何处理?
正如概述中所回答的那样:
Scilab 和 MATLAB 中的数组索引必须是正整数(或逻辑值,但这绝对不是您想要的)。如果您需要 t
在从 0 开始的范围内变化,请始终写 x(t+1)
。如果您需要非整数值,仍然迭代整数并从循环索引计算非整数值。