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

1 vue (au cours des 30 derniers jours)
Nick Vasilakis
Nick Vasilakis le 3 Jan 2021
Commenté : David Hill le 3 Jan 2021
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)));

Réponses (1)

David Hill
David Hill le 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 commentaires
Nick Vasilakis
Nick Vasilakis le 3 Jan 2021
let me give it a try,and i'll come back to you.Thank you very much anyways
David Hill
David Hill le 3 Jan 2021
I don't understand your question. How are you generating A? Would you not constrain A during the generation of it?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by