# keep solution from function into an array

6 Ansichten (letzte 30 Tage)
Qonitat am 8 Mai 2023
Kommentiert: Qonitat am 9 Mai 2023
i want to save solution from a function into an array, there will be x & fval loop input, and i want to save all the incumbent from the previous input to find the maximums ones, can someone help me? sorry for my english
function [x,fval] = BnB(f, A, b, Aeq, beq, lb, ub)
[x,fval] = linprog(f,A,b,Aeq,beq,lb,ub);
[incumbent] = updateincumbent(x,fval)
for i=1:length(x)
if --- && --- && fval>=incumbent
K = ;
K(i)=;
Aeq1 = [--];
beq1 = [--];
Aeq2 = [--];
beq2 = [--];
[x1,fval1] = BnB(f, A, b, Aeq1, beq1, lb, ub);
[x2,fval2] = BnB(f, A, b, Aeq2, beq2, lb, ub);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%incumbent function file
function [incumbent] = updateincumbent(x, fval)
if mod(x,1)==0 & isempty(fval)==0
incumbent=[fval];
else
incumbent=[0];
%here i want to save the incumbent into an array with the previous
%incumbent then saerch the maximum ones
incumbent=max(incumbent)
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

LeoAiE am 9 Mai 2023
function [x, fval, incumbent] = BnB(f, A, b, Aeq, beq, lb, ub, incumbent)
[x, fval] = linprog(f, A, b, Aeq, beq, lb, ub);
[incumbent] = updateincumbent(x, fval, incumbent);
for i = 1:length(x)
if --- && --- && fval >= incumbent
K = ;
K(i) = ;
Aeq1 = [--];
beq1 = [--];
Aeq2 = [--];
beq2 = [--];
[x1, fval1, incumbent] = BnB(f, A, b, Aeq1, beq1, lb, ub, incumbent);
[x2, fval2, incumbent] = BnB(f, A, b, Aeq2, beq2, lb, ub, incumbent);
end
end
function [incumbent] = updateincumbent(x, fval, incumbent)
if mod(x, 1) == 0 && isempty(fval) == 0
incumbent = [incumbent, fval];
else
incumbent = [incumbent, 0];
end
incumbent = max(incumbent);
[x, fval, incumbent] = BnB(f, A, b, Aeq, beq, lb, ub, []);
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Qonitat am 9 Mai 2023
thankyouu it helped a lott

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Linear Least Squares 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!

Translated by