I am writing a Matlab program for simpson's rule I keep getting an error about to many outputs when the program gets to left_simpson = Simpson(a,c,(e1)/2,level, level_max);
What is wrong with settinf left_simpson
to Simpson(a,c,(e1)/2,level, level_max);
?
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