Syntax x = fmin('fun',x1,x2)
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Syntax
x = fmin('fun',x1,x2)
x = fmin('fun',x1,x2,options)
x = fmin('fun',x1,x2,options,P1,P2, ...)
[x,options] = fmin(...)
are not working by matlab? the message from matlab as follows as:
>> f =@(x) x.^3-2*x-5;
>> x = fmin('f', 0, 2)
Undefined function 'fmin' for input arguments of type 'char'.
Did you mean:
>> x = min('f', 0, 2)
Error using min
MIN with two matrices to compare and a working dimension is not supported.
>> x = fminbnd('f', 0, 2)
Cannot find an exact (case-sensitive) match for 'f'
採用された回答
Star Strider
2016 年 8 月 31 日
You’re almost there.
This works:
f =@(x) x.^3-2*x-5;
x = fminbnd(f, 0, 2)
x =
816.4968e-003
18 件のコメント
work wolf
2016 年 8 月 31 日
thankx so much , same meaning x = fmin(fun,x1,x2,options) and x = fminbnd(fun,x1,x2,options) ?
Star Strider
2016 年 8 月 31 日
My pleasure.
There is no fmin function, at least with respect to built-in or ‘core’ MATLAB functions. (I haven’t checked the File Exchange.) If you type doc in the Command Window and then search the Help Browser on fmin, you will get several possible references (depending on the Toolboxes you have installed), none of which are simply fmin.
If you want to define the interval on which to minimise your ‘f’ function, fminbnd is the correct function.
work wolf
2016 年 8 月 31 日
really thankx, fminbnd for minimize a function of one variable. If i want to define the interval on which to minimise more one variable, what is syntax the correct?
Walter Roberson
2016 年 8 月 31 日
If you have multiple variables then use fmincon()
work wolf
2016 年 8 月 31 日
f =@(x) 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
[x,out] = fmins('f',[-1.2, 1])
what was replaced it in matlab 6.0?
Walter Roberson
2016 年 8 月 31 日
That was not valid in MATLAB 5.* . If you are using MATLAB 5, then the 'f' needs to be the name of a function for which there is a corresponding .m file -- so there would have to be f.m that was "function f" in that situation. fminbnd() permits function handles but is only for single variables. fmincon() permits function handles for multiple variables.
Star Strider
2016 年 8 月 31 日
The online documentation only goes back to R13SP2 (6.5.2). The documentation for fmin in that release states:
- Note The fmin function was replaced by fminbnd in Release 11 (MATLAB 5.3). In Release 12 (MATLAB 6.0), fmin displays a warning message and calls fminbnd.
The documentation for fmins in the same documentation states:
- Note The fmins function was replaced by fminsearch in Release 11 (MATLAB 5.3). In Release 12 (MATLAB 6.0), fmins displays a warning message and calls fminsearch.
That’s the best I can do. The MATLAB historiography goes back no further than that.
Note that fminsearch can minimise a function of multiple parameters (I understand that seven is the practical limit), it does not support any constraints. (There is a File Exchange version that permits constraints.)
I don’t know what your version of MATLAB you’re using, so I can’t provide any more specific guidance.
work wolf
2016 年 8 月 31 日
i want change from MATLAB 5.3 to MATLAB 6.0, so i need convert code this
function y = f(x)
y = 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
>>[x,out] = fmins('f',[-1.2, 1]);
x =
1.0000 1.0000
ans =
165
Star Strider
2016 年 8 月 31 日
That appears to be correct. I get essentially the same result with fminsearch. Your ‘out’ variable, according to the available documentation, are the number of steps the function required to converge (as I interpret it).
There does not appear to be any online documentation for MATLAB 6. The next oldest available documentation is for R14 (MATLAB 7.0).
In MATLAB 6.5.2, anonymous functions did not exist (at least that I can determine), so you would have to use inline functions or function files. See Optimization of Inline Objects Instead of M-Files for the documentation on using them.
work wolf
2016 年 8 月 31 日
編集済み: Walter Roberson
2016 年 9 月 1 日
really, thankx for all
>> f =@(x) 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
>> [x,y]= fminsearch(f,[-1.2,1])
x =
1.0000 1.0000
y =
8.1777e-10
but
>> [x,y] = fminunc(f,[-1, 1]);
Warning: Gradient must be provided for trust-region algorithm;
using line-search algorithm instead.
> In fminunc at 383
Local minimum found.
Optimization completed because the size of the gradient is less than the default value of the function tolerance.
<stopping criteria details>
what is the different between fminsearch and fminunc ?
What is the benefit fminunc ?
Star Strider
2016 年 8 月 31 日
I haven’t investigated them in detail, but the principal difference appears to be the algorithms used.
The fminsearch function uses the Nelder-Meade derivative-free algorithm (it does not use the Jacobian of the objective function), and fminunc uses a gradient-descent algorithm that depends on the Jacobian of the objective function to find the minimum.
It’s the end of my day here (UTC-6, 22:25 US MDT) so I’ll follow up with you in the morning.
work wolf
2016 年 8 月 31 日
thankx so much , take care. useful comments help in increasing the knowledge about MATLAB. Let me know, when is objective function accept fminsearch and fminunc or one of them?
Star Strider
2016 年 8 月 31 日
My pleasure.
Both fminsearch and fminunc (and the others) accept inline and anonymous functions, as well as function file functions. The inline functions are now obsolete, replaced by anonymous functions. Use anonymous functions if you can, inline functions otherwise, and function file functions if you need them.
Steven Lord
2016 年 8 月 31 日
work wolf wrote " i want change from MATLAB 5.3 to MATLAB 6.0 "
Why are you upgrading from a 17 year old release (MATLAB 5.3 was released in January 1999) to a nearly 16 year old release (MATLAB 6.0 was released in November 2000)? Why not upgrade to a later release (one that's not a teenager?)
work wolf
2016 年 9 月 1 日
Thank for all, Steven Lord Yeah, your notice right
Star Strider But give error if use objective function banana(x)
f =@(x) 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
with >>fminunc, while >>fminsearch done.
Star Strider
2016 年 9 月 1 日
Both work for me. The fminunc call throws a warning but no error:
x0 = [-1,2];
f =@(x) 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
x_fminunc = fminunc(f,x0)
x_fminsearch = fminsearch(f,x0)
x_fminunc =
0.99999 0.99998
x_fminsearch =
0.99999 0.99998
work wolf
2016 年 9 月 1 日
Relly , thank you sooooo much
Star Strider
2016 年 9 月 1 日
As always, my pleasure!
その他の回答 (1 件)
Walter Roberson
2016 年 8 月 31 日
"Note: The fmin function was replaced by fminbnd in Release 11 (MATLAB 5.3). In Release 12 (MATLAB 6.0), fmin displays a warning message and calls fminbnd."
If you are using MATLAB 5.3 or earlier, that is important information for us to know. If you are using something that old, you would use
x = fmin('f', 0, 2)
but you would also have to have created file f.m with content
function y = f(x)
y = x.^3-2*x-5;
2 件のコメント
work wolf
2016 年 8 月 31 日
x = fmins('fun',x0)
x = fmins('fun',x0,options)
x = fmins('fun',x0,options,[],P1,P2, ...)
[x,options] = fmins(...)
and
z = fzero('fun',x) z = fzero('fun',x,tol)
z = fzero('fun',x,tol,trace)
z = fzero('fun',x,tol,trace,P1,P2,...)
thankx, if the fmin function was replaced by fminbnd, what were replaced fmins and fzero?
Steven Lord
2016 年 8 月 31 日
fmins -> fminsearch
fzero -> fzero
カテゴリ
ヘルプ センター および File Exchange で Optimization についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
