フィルターのクリア

Matlab Optimization problem, minimize a function

2 ビュー (過去 30 日間)
Amine Ben Ayara
Amine Ben Ayara 2016 年 9 月 23 日
コメント済み: Matt J 2016 年 9 月 23 日
Hello, So I have a simple optimization problem that consists of finding a value for a variable that minimizes the difference between two other variables. For example, First input element; An Arbitrary value of X=10. Q=100; B=X*Q; C=50; The objective is to find the value of X that minimizes the difference between (X*Q) & C; f(X)=(X*Q)-C; Is there a function that will give this output or do I need to run a loop that keeps solving for X until it finds a value that minimizes the function f(X)? Thank you so much.

回答 (1 件)

Star Strider
Star Strider 2016 年 9 月 23 日
  3 件のコメント
Alan Weiss
Alan Weiss 2016 年 9 月 23 日
You did not say before that you needed a positive value of P. In that case, use lsqnonneg:
P = lsqnonneg(Q,C)
Alan Weiss
MATLAB mathematical toolbox documentation
Star Strider
Star Strider 2016 年 9 月 23 日
My pleasure.
I believe it definitely could be that simple:
P = 10; % Price = $10
Q = 10; % Quantity = 10
Budget = P*Q; % Total Budget
C = 450; % C = ???
fcn = @(Pstar) norm(Pstar*Q - C); % Objective Function
Pstar1 = fminsearch(fcn, 1) % Determine ‘P*’
Pstar2 = C/Q % Determine ‘P*’
Pstar1 =
45
Pstar2 =
45

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

Community Treasure Hunt

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

Start Hunting!

Translated by