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
You need to specify the returned variable in your function. For e.g., In C++ there’s an explicit
returnstatement – how does MATLAB know what needs to be returned? You specify it in the signature, i.e. in this casef_of_z.