How do you pass in a value to a subfunction in Matlab I am getting output errors?
- by Ben Fossen
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