Why does this piece of code fail in Scilab?
N=1000;
U=rand(N, 1);
X=(9*U - 1)^(1/3);开发者_运维百科
histplot(200, X);
Most likely the code fails because X
is not real. This can happen if U
is smaller than 1/9
, which means that you take the third root of a negative number.
You can find problematic values of U
by checking for whether the values in X
are real.
Is there a '.
' per element operator missing?
X=(9*U - 1).^(1/3);
EDIT:
As Jonas points out Scilab histplot won't accept complex values as argument. MATLAB on the other hand fails because of the missing 'per element' operator.
精彩评论