我正在爲simpson的規則編寫一個Matlab程序當程序到達時,我總是收到一個關於很多輸出的錯誤left_simpson = Simpson(a,c,(e1)/2,level, level_max);
settinf left_simpson
到Simpson(a,c,(e1)/2,level, level_max);
有什麼問題?問題在輸出太多的matlab中
function Simpson(a,b,e1,level, level_max)
level = level + 1;
h = b - a;
c = (a+b)/2;
one_simpson = h*(f(a) + 4*f(c) + f(b))/6;
d = (a+c)/2;
e = (c+b)/2;
two_simpson = h*(f(a) + 4*f(d) + 2*f(c) + 4*f(e))/2;
if level >= level_max
disp('h')
simpson_result = two_simpson;
disp('maximum levels reached')
disp(simpson_result);
if abs(two_simpson - one_simpson) < 15*e1
simpson_result = two_simpson + (two_simpson - one_simpson)/15;
else
left_simpson = Simpson(a,c,(e1)/2,level, level_max);
right_simpson = Simpson(c,b,(e1)/2,level, level_max);
simpson_result = left_simpson + right_simpson;
end
end
密切相關:http://stackoverflow.com/questions/2429888/how-do-you-pass-in-a-value-to-a-subfunction-in-matlab-i-am-getting-output-錯誤 – mtrw 2010-04-02 08:00:39