Minimizing a function with one variable

48 views (last 30 days)
Imane hammou ouali on 10 Jan 2020
Hello expert,
I have to minimize the following function :
but i have just this constraint :
p, w, c are constants
John D'Errico on 11 Jan 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.

Meg Noah on 11 Jan 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)]);
Imane hammou ouali on 14 Jan 2020
thank you very much for the explanation and the detail