Filter löschen
Filter löschen

Calculating optimum using fminbnd

1 Ansicht (letzte 30 Tage)
Gavin Seddon
Gavin Seddon am 13 Aug. 2015
Kommentiert: Gavin Seddon am 14 Aug. 2015
I am trying to use fminbndto calculate an optimum value. I want to define the function and use this with fminbnd. However I get many errors. Clearly it is necessary to use more definitions. My input and the result was:
f = @(x)p1*x^4 + p2*x^3 + p3*x^2 + p4*x + p5
f =
@(x)p1*x^4+p2*x^3+p3*x^2+p4*x+p5
>> >> x = fminbnd(f, 0, 1000) Undefined function or variable 'p1'.
Error in @(x)p1*x^4+p2*x^3+p3*x^2+p4*x+p5
Error in fminbnd (line 215) x= xf; fx = funfcn(x,varargin{:});
>> will someone please either help me modify this or direct me to an appropriate link that will assist me further?
Gavin.

Akzeptierte Antwort

John D'Errico
John D'Errico am 13 Aug. 2015
Bearbeitet: John D'Errico am 13 Aug. 2015
IF you are trying to solve for p1,p2,p3,p4,p5, you CANNOT do it with fminbnd. fminbnd ONLY solves problems with aSINGLE unknown.
IF you are trying to solve for a SYMBOLIC minimum as a function of x, where p1,p2,p3,p4,p5 are all left as symbolic (and therefore unknown) then again, you cannot do this, because fminbnd CANNOT solve symbolic problems.
IF those variables (p1,...p5) have values, and you want to solve for x which yields a minimum, then they need to be assigned.
Finally, IF you are seriously trying to solve for a minimum of a 4th degree polynomial, with known coefficients, and you are trying to use fminbnd, WHY IN THE NAME OF GOD AND LITTLE GREEN APPLES WOULD YOU DO IT THAT WAY????????
Calc 101: Differentiate the polynomial. Then use roots to find the zeros of the derivative polynomial. Throw away the roots that were found outside of your region of interest. Choose the smallest function value the original polynomial yields at the remaining roots. Compare that to the value of the polynomial at the endpoints of the interval of interest, and take the smaller result.
Note that the above scheme will take about 4 lines of code, and will be quite efficient. This scheme will yield the true minimum of the polynomial over that interval. It will not be subject to starting values, or convergence issues for an iterative scheme like fminbnd.
  1 Kommentar
Gavin Seddon
Gavin Seddon am 14 Aug. 2015
Yes, I realise these constants need defining however I was wondering if there are additional caveats. Initially, I wondered about fixing the derivative to 0 to yield a maximum point, which is what I want. However being new to Matlab I am using optimisation tools. It occurs to me to define these constants, that is enough, thanks. Is this the method the software uses?
Thanks again for your help and why do you pray to Apples? Gavin.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by