Calculating optimum using fminbnd
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
John D'Errico
2015년 8월 13일
편집: John D'Errico
2015년 8월 13일
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.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!