How to find a minimum value that calculated from a formulation?

8 ビュー (過去 30 日間)
Le Dung
Le Dung 2017 年 2 月 26 日
コメント済み: Le Dung 2017 年 2 月 26 日
Hi, Now, i have some parameters that range into a region. And i have a formulation that calculated form these parameters. (below code) And i want to find minimum value of the formulation that has to satisfy a condition. And i want to display that minimum value and coresponding values of parameters above. Help me, please. Thank you so much. My code:
x=(50:100);
y=(50:100);
z=(10:30);
Amin=Inf;
Apsmin=Inf;
Mu=155000;
imin=1;
jmin=1;
kmin=1;
for i=1:numel(x)
for j=1:numel(y)
for k=1:numel(z)
Mr = x(i)*y(j)*z(k);
A=x(i)*y(j)*z(k);
Aps=z(k)*1000;
if (Mr>=Mu)&&(A<=Amin)&&(Aps<=Apsmin)
Amin = A;
imin = i;
jmin = j;
kmin = k;
end
end
end
end
disp(Amin);
disp(x(imin));
disp(y(jmin));
disp(z(kmin));

回答 (1 件)

Image Analyst
Image Analyst 2017 年 2 月 26 日
編集済み: Image Analyst 2017 年 2 月 26 日
"And i want to display that minimum value and coresponding values of parameters above." so you can use fprintf(), or sprintf() and helpdlg(), or both ways, like this:
message = sprintf('Amin = %f\nimin = %d, x(imin) = %f\njmin = %d, y(imin) = %f\nkmin = %d, z(imin) = %f\n', Amin, imin, x(imin), jmin, y(jmin), kmin, z(kmin));
% Display in command window:
fprintf('%s', message);
% Display vis popup message
uiwait(helpdlg(message));
  1 件のコメント
Le Dung
Le Dung 2017 年 2 月 26 日
Hi Image Analyst. But when i add a comand such as below: disp('We found value that we need') between two comand as below:
if (Mr>=Mu)&&(A<=Amin)&&(Aps<=Apsmin)
disp('We found value that we need')
Amin = A;
when program runs. It will present on destop " We found value that we need" for all cases. So, why?

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by