Syntax x = fmin('fun',x1,x2)
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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일
1 개 추천
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.
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일
0 개 추천
"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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
