Problem using function handles
古いコメントを表示
I have a homework problem where I have to code a function for a bisection root finder. One of the inputs to the function is the handle to the function to be searched, but I'm having problems implementing it. I'm gonna simplify this from my homework, but let's say I have a test function thats:
function [y] = f(x)
y = x - cos(x);
end
And my bisection root finder is:
function [root] = bisection(func, upper_bound, lower_bound)
func_ub = @func(upper_bound);
func_lb = @func(lower_bound);
root = (func_up + func_lb)/2;
end
If I enter bisection(f,0,2) in the command window matlab returns the error:
Not enough input arguments.
Error in f (line 2)
y = x - cos(x);
I'm trying to get some values for func_ub and func_lb by plugging in my upper_bound and lower_bound into my function f, some help would be greatly appreciated. Thanks!
1 件のコメント
Stephen23
2018 年 9 月 30 日
回答 (1 件)
Rik
2018 年 9 月 29 日
Maybe you mean this?
bisection(@f,0,2)
4 件のコメント
Jarrett Barber
2018 年 9 月 29 日
Rik
2018 年 9 月 29 日
You don't need the @ in the bisection function
Jarrett Barber
2018 年 9 月 29 日
Rik
2018 年 9 月 29 日
You're welcome. If this solved your problem, please hit the 'accept answer' button. If not, feel free to post your remaining issues in a comment below.
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!