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

조회 수: 1(최근 30일)
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
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?

댓글을 달려면 로그인하십시오.

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by