How can I implement a loop to find the minimum among 5 values
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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)));
0 Kommentare
Antworten (1)
David Hill
am 3 Jan. 2021
Are you not allowed to use the min() function?
function D = myfun(A)
D=min([.1 3 5 8 12]./cumprod(A));
4 Kommentare
David Hill
am 3 Jan. 2021
I don't understand your question. How are you generating A? Would you not constrain A during the generation of it?
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!