4 views (last 30 days)

Show older comments

This is the first equation in AMPL:

minimize Total_Cost:

sum {i in CONTROLLER} kappa_c[i] *

sum {j in LOCATION} tcn[i, j]

*tcn is a binary variable

This is after i tried convert it to MATLAB form:

% these values are given%

CONTROLLER = 9;

kappa_c = {1,2,3,4,5,6,7,8,9};

LOCATION = 9;

sum = 0;

for i = 1:CONTROLLER

sum = sum + kappa_c{i};

sum1 = 0;

for j = 1:LOCATION

sum1 = sum1 + tcn{i;j};

end

ans1 = sum1 * sum ;

end

display(ans1)

Walter Roberson
on 15 Nov 2017

Your AMPL definition uses j as the loop control variable twice, and uses the undefined variable i . Your translation of it into MATLAB would be for the slightly different

minimize Total_Cost:

sum {i in CONTROLLER} kappa_c[i] *

sum {j in LOCATION} tcn[i, j]

Yogananda Jeppu
on 11 Nov 2017

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

Start Hunting!