Minimizing a function with one variable
7 次查看(过去 30 天)
显示 更早的评论
Hello expert,
I have to minimize the following function : ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261186/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261186/image.png)
but i have just this constraint :![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261187/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261187/image.png)
p, w, c are constants
thank you in advance for answering me
1 个评论
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
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
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!