Minimizing a function with one variable

10 次查看(过去 30 天)
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