Finding the minimum of a function
古いコメントを表示
My function is supposed to return the minimum y-value, fmin, of the function described in the input function handle, funhan, in the interval, [x1, x2]. What am I doing wrong?
function fmin = findMin(funhan, x1, x2)
[~, fmin] = fmindbnd(@funhan(x),x1,x2);
and I already wrote the pre-exisiting function square_plus_one (which will be called in the test case)
function y = square_plus_one(x)
y= x.^2 + 1
These are what the Test Cases are supposed to run--but i can't run the test cases without an error
>> fh = @square_plus_one;
>> low = 3; hi = 5;
>> findMin(fh,low,hi)
ans = 10.0003
>> fh = @cos;
>> low = 3; hi = 4;
>> findMin(fh,low,hi)
ans = -1.0000
2 件のコメント
Star Strider
2012 年 10 月 14 日
I don't see any errors. What were you expecting?
Walter Roberson
2012 年 10 月 14 日
The minimum of x^2+1 over 3 to 5 would be 10 not 10.0003
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Strategy & Logic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!