MATLAB Answers

Minimizing a function with one variable

48 views (last 30 days)
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 Comment
John D'Errico
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.

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by