Problem with while loop

1 visualizzazione (ultimi 30 giorni)
Siva
Siva il 19 Ott 2017
Commentato: Siva il 19 Ott 2017
I wrote 3 functions and i wanted to link them in main function. In the main function i wrote a while loop . i am facing problem with this while loop. . The loop is running with initial values, i.e., it is not updating the values of rcapa, capaPAMin, and Bineq. The main function runs as follows
How to correct this problem.
global Bineq1; capaPAMin = inf; Bineq2 = capaPAMin; Bineq = vertcat(Bineq1,Bineq2); iter = 1; while(iter <=15) DA2 = @(Bineq,capaPAMin) somefunction(c1,c2,c3,c4,c8,capaPAMin,Aineq,Bineq,Aeq,Beq,lb2,ub2); [yd2,DAC2] = DA2(Bineq,capaPAMin); td2 = yd2(1345:1728); -- -- -- rcapa -- -- PA2 = @(rcapa) somotherfunction(c5,c6,c7,Aineq,Bineq,Aeq,rcapa,lb1,ub1); [yp2,PAC2] = PA2(rcapa); b = yp2(385:576); -- -- capaPA -- -- if capaPAMin > capaPA capaPAMin = capaPA; end Bineq2 = capaPAMin; Bineq = vertcat(Bineq1,Bineq2); iter = iter + 1; end
  2 Commenti
KL
KL il 19 Ott 2017
Please format your code. To do that, select the code in your question, click the {} Code button. That way, it is much easier to read.
Siva
Siva il 19 Ott 2017
I wrote 3 functions and i wanted to link them in main function. In the main function i wrote a while loop . i am facing problem with this while loop. . The loop is running with initial values, i.e., it is not updating the values of rcapa, capaPAMin, and Bineq. The main function runs as follows
How to correct this problem.
global Bineq1; capaPAMin = inf; Bineq2 = capaPAMin; Bineq = vertcat(Bineq1,Bineq2); iter = 1; while(iter <=15) DA2 = @(Bineq,capaPAMin) somefunction(c1,c2,c3,c4,c8,capaPAMin,Aineq,Bineq,Aeq,Beq,lb2,ub2); [yd2,DAC2] = DA2(Bineq,capaPAMin); td2 = yd2(1345:1728); -- -- -- rcapa -- -- PA2 = @(rcapa) somotherfunction(c5,c6,c7,Aineq,Bineq,Aeq,rcapa,lb1,ub1); [yp2,PAC2] = PA2(rcapa); b = yp2(385:576); -- -- capaPA -- -- if capaPAMin > capaPA capaPAMin = capaPA; end Bineq2 = capaPAMin; Bineq = vertcat(Bineq1,Bineq2); iter = iter + 1; end

Accedi per commentare.

Risposta accettata

KL
KL il 19 Ott 2017
Modificato: KL il 19 Ott 2017
In the code you've provided, the variables ( rcapa, capaPA) are not defined.
Moreover even if you define it in the beginning, they are not influenced by any of your functions. So they wouldn't change but stay in its initial conditions.
  1 Commento
Siva
Siva il 19 Ott 2017
I am writing below the full code. The loop is not updating the values of rcapa, capaPAMin, and Bineq. How to fix this problem
global Bineq1;
lb = zeros(1,1728);
[yd1,DAC1] = DAgent1([],[],[],[],[],[],[],[],lb,options );
capaPAMin = inf;
iter = 1;
Atd14 = diag(ones(1,192),0);
Atd24 = diag(ones(1,180),12)
Atd4 = Atd14 + Atd24;
O4 = zeros(192,192);
Atd4 = horzcat(Atd4,O4);
sigmatdpfmt = Atd4;
size(Atd4);
td1= yd1(1345:1728);
p1sigmarcapa = diag(ones(1,24),0);
psigmarcapa = repmat(p1sigmarcapa,[1,8]);
size(psigmarcapa);
psigmab = diag(ones(1,24),0);
psigmab = repmat(psigmab,[1,8]);
size(psigmab);
fcapa1 =sigmatdpfmt*td1;
rcapa = fcapa1;
lb1 = zeros(1,576);
PA1 = @(rcapa) PAgent([],[],[],[],[],[],rcapa,lb1,[],[] );
[yp1,PAC1]= PA1(rcapa);
TC1= DAC1 + PAC1;
results = zeros(iter,4);
results(1,1) = 1;
results(1,2) = DAC1;
results(1,3) = PAC1;
results(1,4) = TC1;
b = yp1(385:576);
capaPA = (psigmarcapa*rcapa) - (psigmab*b);
if capaPAMin > capaPA
capaPAMin= capaPA;
end
lb2 = zeros(1,1920);
Bineq2 = capaPAMin;
Bineq = vertcat(Bineq1,Bineq2);
while (iter <=5)
DA2 = @(Bineq,capaPAMin)DAgent( [],[],[],[],[],capaPAMin,[],Bineq,[],[],lb2,[],[] );
[yd2,DAC2] = DA2(Bineq,capaPAMin);
td2 = yd2(1345:1728);
p1sigmarcapa = diag(ones(1,24),0);
psigmarcapa = repmat(p1sigmarcapa,[1,8]);
size(psigmarcapa);
psigmab = diag(ones(1,24),0);
psigmab = repmat(psigmab,[1,8]);
size(psigmab);
fcapa3 =sigmatdpfmt*td2;
rcapa1 = fcapa3;
lb1 = zeros(1,576);
PA2 = @(rcapa1) PAgent([],[],[],[],[],[],rcapa1,lb1,[],[] );
[yp2,PAC2]= PA2(rcapa1);
b1 = yp2(385:576);
capaPA = (psigmarcapa*rcapa1) - (psigmab*b1);
if capaPAMin > capaPA
capaPAMin= capaPA;
end
Bineq2 = capaPAMin;
Bineq = vertcat(Bineq1,Bineq2);
TC2 = DAC2 + PAC1;
results(iter,1) = iter;
results(iter,2) = DAC2;
results(iter,3) = PAC2;
results(iter,4) = TC2;
iter = iter + 1;
end

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by