I have A,B,C,D,E values all in size 1x1155. A=[1.0001, 1.0005, 1.00010,...,1.0009]. similar to B, C, D and E. I need (A(1)+B(1))/(C(1)+D(1)E(1)) + (A(2)+B(2))/(C(2)+D(2)E(2)) + ... + (A(1155)+B(1155))/(C(1155)+D(1155)E(1155)). Therefore i need each individual variable using loop rather than defining one by one from 1 to 1155. Is there a way to do that in Matlab?

  • $\begingroup$ Look the example of this: mathworks.com/help/optim/ug/optimproblem.html The objective of the example is x(1) + x(2). It is easy to type manually. But I have 1155 variable [meaning x(1)+x(2)+...+x(1155)] to optimise and it will take ages to type manually. Thus I must use loop. My main part is to solve optivar('x',1,1155,'LowerBound',0,'UpperBound',0) - 1155 variables. How to use the loop in here? $\endgroup$ – Poohish... Nov 8 '19 at 10:51

Use pointwise vector operations:

% given A,B,C,D,E
A = rand(1,1155);
B = rand(1,1155);
C = rand(1,1155);
D = rand(1,1155);
E = rand(1,1155);
% compute F
F = (A+B)./(C + D.*E);
| improve this answer | |
  • $\begingroup$ Sorry this is not what i meant $\endgroup$ – Poohish... Nov 8 '19 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.