Recursion 分段冲突-在八度音阶中停止我自己
我有以下倍频程代码,尝试使用辛普森方法实现自适应正交:Recursion 分段冲突-在八度音阶中停止我自己,recursion,octave,numerical-integration,Recursion,Octave,Numerical Integration,我有以下倍频程代码,尝试使用辛普森方法实现自适应正交: function integral = adaptive2(f, a, b, TOL, count) max_count = 20; disp("hello world"); disp(count); h = (b-a)/2; x_1 = a; x_2 = (b-a)/2; x_3 = b; w_0 = a; w_1 = (b-a)/4; w_2 = (b-a)/2; w_3 = 3*(b-a)/4; w_4 = b; initial
function integral = adaptive2(f, a, b, TOL, count)
max_count = 20;
disp("hello world");
disp(count);
h = (b-a)/2;
x_1 = a;
x_2 = (b-a)/2;
x_3 = b;
w_0 = a;
w_1 = (b-a)/4;
w_2 = (b-a)/2;
w_3 = 3*(b-a)/4;
w_4 = b;
initial_1 = (f(x_1) + 4*f(x_2) + f(x_3));
i1 = (h/3) * initial_1;
initial_2 = (f(w_0) + 4*f(w_1) + 2*f(w_2) + 4*f(w_3) + f(w_4));
i2 = (h/6) * initial_2;
disp(i1);
disp(i2);
if count == max_count
integral = i2;
return;
endif
if abs(i1 - i2) < (10 * TOL)
integral = i2;
return;
endif
count = count + 1;
disp(count);
disp(TOL);
integral = (adaptive2(f, a, (b+a)/2, TOL/2, count) + adaptive2(f, (b+a)/2, b, TOL/2, count));
return;
我得到以下错误:
panic segmentation violation - stopping myself
这段代码中发生了什么我需要修复的问题?它是一个无限循环吗?最后的递归调用是否不正确?我能够重现这个segfault,它不应该发生: 关于我的设置:
octave:1> plot(1)
Insufficient GL support
Insufficient GL support
panic: Segmentation fault -- stopping myself...
attempting to save variables to 'octave-workspace'...
save to 'octave-workspace' complete
Segmentation fault
重现错误的步骤:
octave:1> plot(1)
Insufficient GL support
Insufficient GL support
panic: Segmentation fault -- stopping myself...
attempting to save variables to 'octave-workspace'...
save to 'octave-workspace' complete
Segmentation fault
gnuplot: unable to open display 'localhost:10.0'
gnuplot: X11 aborted.
双因素身份验证淘汰了octave在绘图上执行X11转发的能力。这可能是某种保护功能。GNU Octave不应该出现故障,所以这是一个bug。您使用的是哪个版本、操作系统和版本?它在这里没有崩溃(linux上的octave 3.8.2),但似乎陷入了一个循环。您可以尝试减少
max_count
,以使用较少的递归调用对其进行调试。