How do you pass in a value to a subfunction in Matlab I am getting output errors?

Posted by Ben Fossen on Stack Overflow See other posts from Stack Overflow or by Ben Fossen
Published on 2010-03-12T01:19:10Z Indexed on 2010/03/12 1:37 UTC
Read the original article Hit count: 266

Filed under:

Below is my code in Matlab I am having trouble with the line sum = (h/2) * (f(a) + f(b)) + h; Matlab says I have to many outputs when I try to call the f(x) function. Is my problem with the f(x) function

function Trapezoid_Uniform(a,b,n)
    h = (b - a)/n;
    sum = (h/2) * (f(a) + f(b)) + h;

    for i = 1:n-1
        x = a + i*h;
        sum = sum + f(x);
    end

    sum = sum*h;
    disp(sum);
end

function f(z)
    f = exp(z);
end

© Stack Overflow or respective owner

Related posts about matlab