2016-04-30 180 views
-1

我不明白为什么会出现这个错误,我一直在油炸我的大脑但找不到它。从第51行第12列调用的错误为:subscript indices must be either positive integers less than 2^31 or logicals,我将在下面的代码中标记它。在Octave脚本中找不到我的语法错误

我不明白为什么我的代码解释我使用xintv4作为下标。 f2是一个功能,我称它来评估一组x值...

f2 [email protected](x) x.^2 .* e.^(-x).*sin(pi.*x); 

a4 = -1; 
    b4 = 1; 
    c4 = 0.84685; 

    for N4 = [10]#, 100, 1000, 10000] 

     disp(""); 

     B = 1;    

     for p4 = 1:2 

     xintv4 = rand(1,N4)*2-1; 
     yintv4 = rand(1,N4)+c4; 
     f2 = f2(xintv4)+c4; #error points to this line at the "=" sign 
     nf4 = 0; 
     nf4count = 0; 
     nf4 = f2./yintv4;   

     for k = 1:N4 

       if nf4(k) >= 1 

        nf4count += 1; 

       else 

        nf4count += 0; 

       end     

     endfor 

     #disp("nf:");disp(nf); 
     #disp("nfcount:");disp(nfcount); 

     I4(p4) = ((B+c4)*(b4-a4)*(nf4count/N4))-(c4*(b4-a4));   

     endfor 

     meanI4 = mean(I4); 
     stdevI4 = std(I4); 

     disp("N = "); disp(N4); 
     disp("Mean of the integral using method 2:");disp(meanI4); 
     disp("Standard deviation of the integral using method 2:");disp(stdevI4);  

    endfor 

我试图将其更改为for p4 = 1for p4 = 1:2玩弄这工作,但我休息的时候我增加循环2,3或4(等)。

添加了MATLAB标签,因为它们是相似的语言。

+1

最小的调试方法:在错误后测试'f2(xintv4)',然后只是'f2' ... – ederag

回答

2
f2 = f2(xintv4)+c4; 

您分配匿名函数f2变量f2返回值。第二次,f2不再是一个函数名称。

+0

Lol woops .... yea就是这样。谢谢! – whatwhatwhat