Borrar filtros
Borrar filtros

Calculating optimum using fminbnd

1 visualización (últimos 30 días)
Gavin Seddon
Gavin Seddon el 13 de Ag. de 2015
Comentada: Gavin Seddon el 14 de Ag. de 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.

Respuesta aceptada

John D'Errico
John D'Errico el 13 de Ag. de 2015
Editada: John D'Errico el 13 de Ag. de 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 comentario
Gavin Seddon
Gavin Seddon el 14 de Ag. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by