trying to use fminbnd to minimize a function with resolution 0.01

조회 수: 2 (최근 30일)
function [e,t,lf]=f2(q,w)
e=fminbnd(@fun,q,w)
t=(1000/e)-(0.25*pi*e) (%these are final values please ignore them)
lf=(50*pi*r)+(((2*r)+(2*l))*40); (%these are final values please ignore them)
function [c]=fun(r)
r=q:0.01:w;
l=(1000./r)-(0.25*pi.*r);
c=(50*pi.*r)+(((2.*r)+(2.*l))*40);(%trying to minimize this function but i couldnt using fminbnd )
end
end
but im getti
ng these errors
Error using fminbnd (line 220)
User supplied objective function must return a scalar value.
Error in f2 (line 2)
e=fminbnd(@fun,q,w)
trying to learn matlab bascis on my own
please help me in this regard

채택된 답변

Matt J
Matt J 2020년 6월 5일
편집: Matt J 2020년 6월 5일
You cannot use fminbnd to guarantee a distance of 0.01 (or any other distance) to the global minimum, but typically you will do much better than that with the default tolerances. To eliminate your fminbnd error message remove the line, r=q:0.01:w,
e=fminbnd(@fun,q,w)
function [c]=fun(r)
%r=q:0.01:w;
l=(1000./r)-(0.25*pi.*r);
c=(50*pi.*r)+(((2.*r)+(2.*l))*40);
end
You can however guarantee a distance of 0.01 if you use exhaustive search, instead of fminbnd. That would look like,
r=q:0.01:w;
[~,minloc]=min(fun(r));
e=r(minloc)
function [c]=fun(r)
l=(1000./r)-(0.25*pi.*r);
c=(50*pi.*r)+(((2.*r)+(2.*l))*40);
end
  댓글 수: 5
Matt J
Matt J 2020년 6월 5일
편집: Matt J 2020년 6월 5일
It is probably intended that you to set the TolX parameter to 0.01, as in the example below. But note that this is not the same as varying r in increements of 0.01.
q=5;w=10;
e=fminbnd(@fun,q,w,optimset('TolX',0.01))
function [c]=fun(r)
l=(1000./r)-(0.25*pi.*r);
c=(50*pi.*r)+(((2.*r)+(2.*l))*40);
end
AJAY CHANDRA DORAGARI
AJAY CHANDRA DORAGARI 2020년 6월 5일
yes sir, it might be asking to find with a tolerence of 0.01.
thank you sir
thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by