フィルターのクリア

returning the input value with maximum output

1 回表示 (過去 30 日間)
azie
azie 2013 年 6 月 25 日
i want to get the input that maximize the output. how to get this value?
here is the programe code.
a=[ 1 2 3];
b=[7 4 2];
y=2.*a+5.*b; % the output should be y = [37 24 16]
ymax=max(y); %37 where the value a=1,b=7
so, what function can i use to return the value a=1 and b=7?

採用された回答

David Sanchez
David Sanchez 2013 年 6 月 25 日
編集済み: Andrei Bobrov 2013 年 6 月 25 日
There are several choices to find minimum/maximum values. You can take a look at the built-in function fmincon for example. In your case, if the data you present is the data, you can do something like this:
% find the maximum value in the output array:
[y_max max_indes] = max(y);
a_max = a(max_index); % get the corresponding value from the _a_ array
b_max = b(max_index); % get the corresponding value from the _b_ array
  2 件のコメント
azie
azie 2013 年 6 月 25 日
thats give me an error said " undefined function 'max_index' ".
do i need to define the max_index?
Iain
Iain 2013 年 6 月 25 日
Correct his typo: :P
[y_max max_index] = max(y);

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBoundary Conditions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by