Calling a function within another function
Show older comments
So I'm writing a bisection method. The beginning of the method looks like this.
function root = Bisect ( xl , xu , eps , imax, f )
i = 1;
fl = f(xl);
So I pass in xl (note that l is the letter L and not a one) when I call this function and it then calls the function f. Here's my function f:
function y = f(x)
y = (pi*x^2)*((3*4.1 - x)/3);
end
The problem is that I called the bisection function with the input "Bisect(0, 4.1, 0.0001, 20, f)" and I keep getting this error:
>> Bisect(0, 4.1, 0.0001, 20, f)
Not enough input arguments.
Error in f (line 3)
y = (pi*x^2)*((3*4.1 - x)/3);
So what am I doing wrong?
Accepted Answer
More Answers (1)
Use '@' to specify a handle to f(),
Bisect(0, 4.1, 0.0001, 20, @f)
Categories
Find more on Environment and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!