Azzera filtri
Azzera filtri

trying to use fminbnd to minimize a function with resolution 0.01

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Matt J
Matt J il 5 Giu 2020
Modificato: Matt J il 5 Giu 2020
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 Commenti
Matt J
Matt J il 5 Giu 2020
Modificato: Matt J il 5 Giu 2020
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 il 5 Giu 2020
yes sir, it might be asking to find with a tolerence of 0.01.
thank you sir
thank you very much

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by