开发者

Problem in matlab with too many outputs

开发者 https://www.devze.com 2022-12-25 04:51 出处:网络
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

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 =开发者_如何学Go 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


Your function statement, the first line in your code, doesn't declare what Simpson returns. I don't know what Matlab does with such a declaration. I think you should re-write Simpson to explicitly return a value, or values. Have a look at the Matlab documentation for how to do that.

Once you have declared what Simpson returns, then you will probably be able to avoid the 'too many outputs' problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消