Minimizing a function with one variable

조회 수: 9 (최근 30일)
Imane hammou ouali
Imane hammou ouali 2020년 1월 10일
댓글: Imane hammou ouali 2020년 1월 14일
Hello expert,
I have to minimize the following function :
but i have just this constraint :
p, w, c are constants
thank you in advance for answering me
  댓글 수: 1
John D'Errico
John D'Errico 2020년 1월 11일
This is a quadratic function of x, a scalar variable? While fminbnd seems simple enough, high school algebra should suffice too. There are too many undefined variables listed be sure what your problem really is, as well as an unreadable function as you have inserted it. Are some of those x's multiplication symbols?
If really is just a quadratic, then the min occurs either at an end point of the interval, or at the minimum of the quadratic.

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

채택된 답변

Meg Noah
Meg Noah 2020년 1월 11일
Is this what you're looking for?
p = pi;
w = 9*pi/56;
c = 5;
rmin = -40;
rmax = 40;
% inline function
fun = @(x)(0.5*p*x + 0.5*w*(x-c)^2);
options = optimset('PlotFcns',@optimplotfval,'TolX',1e-20,'MaxIter',50000);
% minimization
[r,fval,exitflag,output] = fminbnd(fun,rmin,rmax,options);
disp(['Value of r = ' num2str(r)]);
  댓글 수: 5
Meg Noah
Meg Noah 2020년 1월 14일
You're quite welcome.
The minimizer, as you noted, is called:
fminbnd
The arguments of this minimizer are:
  • The function name (either anonymous or a separate .m function will do)
  • The min and max of the valid range of solutions
  • Options for the minimizer such as maximum number of steps, tolerance for terminating (determining solution), and even the joyful plotting
The outputs of the mimizer are:
  • the value of x such that f(x) is at its mimimum, call it xmin
  • the value f(xmin)
  • status flag indicating success or failure
  • output is a structure with information about the conditions under which the minimum was determined
The options are described in the documentation for the fminbnd function:
From the documentation:
fminbnd is a function file. The algorithm is based on golden section search and parabolic interpolation. Unless the left endpoint x1 is very close to the right endpoint x2, fminbnd never evaluates fun at the endpoints, so fun need only be defined for x in the interval x1 < x < x2.
If the minimum actually occurs at x1 or x2, fminbnd returns a point x in the interior of the interval (x1,x2) that is close to the minimizer. In this case, the distance of x from the minimizer is no more than 2*(TolX + 3*abs(x)*sqrt(eps)). See [1] or [2] for details about the algorithm.
[1] Forsythe, G. E., M. A. Malcolm, and C. B. Moler. Computer Methods for Mathematical Computations. Englewood Cliffs, NJ: Prentice Hall, 1976.
[2] Brent, Richard. P. Algorithms for Minimization without Derivatives. Englewood Cliffs, NJ: Prentice-Hall, 1973.
Imane hammou ouali
Imane hammou ouali 2020년 1월 14일
thank you very much for the explanation and the detail

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by