How can I implement a loop to find the minimum among 5 values

1 回表示 (過去 30 日間)
Nick Vasilakis
Nick Vasilakis 2021 年 1 月 3 日
コメント済み: David Hill 2021 年 1 月 3 日
Hello and happy new year everyone.
I want to create a loop that finds the minimum among the 5 values s(1)-s(5) and put it into a different variable(let's say x).Then place this variable x into D so that the division could happen.Note that the values of A(1)-A(5) are numbers that are imported automatically from optimization tool,meaning that I can't interefere to them.Also I want the multiplication of A(1)-A(5) to be exactly 10.000.
The code that I have used is given below:
*P.S:I don't know if this helps,but I have been given some maximum values for A(1)-A(5),but the instructor told me that those values should be put only in Optimization tool.Also the problem that I have to solve,is of optimization(of course)
function D = myfun(A)
s(1) =0.1/A(1);
s(2) =3/(A(1)*A(2));
s(3) =5/(A(1)*A(2)*A(3));
s(4) =8/(A(1)*A(2)*A(3)*A(4));
s(5) =12/(A(1)*A(2)*A(3)*A(4)*A(5));
D = -( ./ A(5)*sqrt(A(4)^2*(A(3)^2*(A(2)^2*(A(1)*10^(-10) + 10^(-6) ) + 10^(-4) ) + 10^(-4) )+ 10^(-2)));

回答 (1 件)

David Hill
David Hill 2021 年 1 月 3 日
Are you not allowed to use the min() function?
function D = myfun(A)
D=min([.1 3 5 8 12]./cumprod(A));
  4 件のコメント
Nick Vasilakis
Nick Vasilakis 2021 年 1 月 3 日
let me give it a try,and i'll come back to you.Thank you very much anyways
David Hill
David Hill 2021 年 1 月 3 日
I don't understand your question. How are you generating A? Would you not constrain A during the generation of it?

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

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by