Minimizing a function with one variable
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Imane hammou ouali
el 10 de En. de 2020
Comentada: Imane hammou ouali
el 14 de En. de 2020
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 comentario
John D'Errico
el 11 de En. de 2020
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.
Respuesta aceptada
Meg Noah
el 11 de En. de 2020
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 comentarios
Meg Noah
el 14 de En. de 2020
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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!