How to find max and min value of a function ?

127 ビュー (過去 30 日間)
Ani Asoyan
Ani Asoyan 2020 年 5 月 22 日
回答済み: Walter Roberson 2020 年 5 月 22 日
Hi ... I have a function u_g
a=2; b=2; c=1; e=0.75 ; l=0.5;
u_g = @(x, x_e, N)(-0.5*a*x.^2+b*(x-x_e)-c*(N.^l)+e*u_p(x,x_e,N));
x and N are variables, the rest of them are parameters... I want to find the value of x which will bring u_g the maximum value and corresponding max value of u_g
and I want to find the value of N which will bring minimum value to u_g and corresponding value of u_g ..how can I do it ?.. do I have to fix one of the variables?
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 5 月 22 日
u_p is a function?
Ani Asoyan
Ani Asoyan 2020 年 5 月 22 日
yes u_p is a function... sorry I changed what I wanted.
x_e is also a variable
I want to find the values of N and x which will maximize u_g function and the max value of function
and also I want to find the value of N which will maximize u_g function given the value of x (for example x=0) ..
can I do that? .. Do I have to give x_e a value ?

サインインしてコメントする。

回答 (3 件)

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020 年 5 月 22 日
編集済み: Abdolkarim Mohammadi 2020 年 5 月 22 日
Finding the value of inputs that minimzes or maximizes the objective function value is an optimization problem. If your function is linear, then you run the following code and optimize your function:
[x, fval] = linprog (u_g, [], []);
If your function is unimodal and relatively smooth, then you run the following code and optimize your function:
[x, fval] = fmincon (u_g, x0, [], []);
And if the landscape of your function is unknown, i.e., you don't know whether it is linear, nonlinear, multi-modal, non-smooth, etc, then you run the following code and optimize your function:
nvars = 3;
[x, fval] = ga (u_g, nvars);
You can refer to the documentation of each solver for more information.
  2 件のコメント
John D'Errico
John D'Errico 2020 年 5 月 22 日
You seem to be advocating linprog for all problems. (At least those I've seen you answer.) Note that this is NOT a linear objective, so linprog is completely useless here.
Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020 年 5 月 22 日
I just wanted to give a general idea of the optimization tools besides the nonlinear ones that are suitale for those problems.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2020 年 5 月 22 日
a=2; b=2; c=1; e=0.75 ; l=0.5;
u_g = @(x, x_e, N)(-0.5*a*x.^2+b*(x-x_e)-c*(N.^l)+e*u_p(x,x_e,N));
funmin = @(xxeN) u_g(xxeN(1), xxeN(2), xxeN(3));
funmax = @(xxeN) -u_g(xxeN(1), xxeN(2), xxeN(3));
lb = [-10 -10 -10]; %adjust as appropriate
ub = [10 10 10]; %adjust as appropriate
xxeN0 = [-.1 .2 .3]; %initial guess
[best4min, fvalmin] = fmincon(funmin, xxeN0, [], [], [], [], lb, ub);
[best4max, fvalmax] = fmincon(funmax, xxeN0, [], [], [], [], lb, ub);

Cristian Garcia Milan
Cristian Garcia Milan 2020 年 5 月 22 日
I think that what you want is the function
fminbnd(fun)
that finds local minimum.
If you use
fminbnd(-fun)
you will get it max.
  3 件のコメント
Cristian Garcia Milan
Cristian Garcia Milan 2020 年 5 月 22 日
How about using symbolic toolbox? Then you can derivate alomg x or N and solve making equal 0
Ani Asoyan
Ani Asoyan 2020 年 5 月 22 日
you mean syms x? ,, how can I do that properly?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by