无法找出 Octave 脚本中的语法错误
Can't figure out my syntax error in Octave script
不明白为什么会出现这个错误,绞尽脑汁也找不到。错误显示:subscript indices must be either positive integers less than 2^31 or logicals
从第 51 行第 12 列调用,我将在下面的代码中标记它。
我不明白为什么我的代码解释我正在使用 xintv4
作为下标。 f2
是一个函数,我调用它来计算一组 x 值...
f2 =@(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 = 1:2
更改为 for p4 = 1
来玩弄它并且这有效,但是当我将循环增加到 2,3 或 4(等)时我中断了。
添加了 MATLAB 标签,因为它们是相似的语言。
f2 = f2(xintv4)+c4;
您将匿名函数 f2
的 return 值分配给 变量 f2
。第二次,f2
不再是函数名。
不明白为什么会出现这个错误,绞尽脑汁也找不到。错误显示:subscript indices must be either positive integers less than 2^31 or logicals
从第 51 行第 12 列调用,我将在下面的代码中标记它。
我不明白为什么我的代码解释我正在使用 xintv4
作为下标。 f2
是一个函数,我调用它来计算一组 x 值...
f2 =@(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 = 1:2
更改为 for p4 = 1
来玩弄它并且这有效,但是当我将循环增加到 2,3 或 4(等)时我中断了。
添加了 MATLAB 标签,因为它们是相似的语言。
f2 = f2(xintv4)+c4;
您将匿名函数 f2
的 return 值分配给 变量 f2
。第二次,f2
不再是函数名。