Yes. You are doing something wrong. Admittedly, others have made the same mistake. It comes down to understanding how MATLAB looks at a line of code to be executed.
See that this works:
fzero(@f,-1)
ans =
-0.7854
And it fails here:
fzero(f,-1)
Not enough input arguments.
Error in f (line 6)
A2 = L3*cos(theta) - x1;
Why? Because in the first case, I explicitly told MATLAB that f was a function to be passed in.
As you have tried to call fzero, see what happened. When you try to execute the expression fzero(f,-1), MATLAB see the f, and tries to evaluate the function f. MATLAB does not see the outer call to fzero and realize what you want it to do. MATLAB is very literal. It does exactly as you tell it. MATLAB sees f, and says it must evaluate a function with no inputs, but the function f has an input argument. Ergo, the error message.
Finally, had you done this, it would also have worked.
fzero('f',-1)
ans =
-0.7854
Here MATLAB recognizes that you passed in a string argument, so it assumes that to be the name of the function.
Best Answer