# How to execute multiple optimized values for x according to n, using fmincon

2 Ansichten (letzte 30 Tage)
Maheen Fazal am 17 Mai 2019
Kommentiert: Maheen Fazal am 17 Mai 2019
Hello, kindly help me in finding n optimal values for x (x is a vector not single valued).
e.g. i have the main code
function Rsum Simple(x)
global n
R=20*1000;
Rn =x*R;
Rsum=sum(Rn);
end
by using fmincon i am optimizing x
clear all
clc
global n
n_vec=2:2:6;
throughput=[];
for n=n_vec
initial_guess=0.00002;
x0=initial_guess;
lb=0;
ub=0.7;
A = [];
b = [];
Aeq=[];
Beq=[];
[x,fval]= fmincon(@(x) Simple(x),x0,A,b,[],[],lb,ub);
max=-(fval);
throughput=[throughput max];
end
after executing first attempt i want to get 2 optimized values of x,in 2nd i need 4 optimized values and in 3rd time x=6, but i dont know how to execute it. can any body help me out to find multiple values of x(with respect to n).??
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Titus Edelhofer am 17 Mai 2019
Bearbeitet: Titus Edelhofer am 17 Mai 2019
Hi,
there are a couple of things I don't understand: you say "x is a vector"? But you always start with x0=initial_guess, which is a scalar. Perhaps this is the first change you would need to do:
x0 = repmat(initial_val, n, 1);
to make x0 a vector.
Second, your objective function is strange. Variable S is not used? x = [0...0] is the solution for the function you wrote.
Titus
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Maheen Fazal am 17 Mai 2019
Sorry it was by mistakenly wrriten, okay Sir will changes in initial guess.

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (2)

Maheen Fazal am 17 Mai 2019
Bearbeitet: Maheen Fazal am 17 Mai 2019
just let me know if i have to find n optimal values for x then how could i find?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Maheen Fazal am 17 Mai 2019
can i also change uper and lower bounds accordingly?
##### 2 KommentareKeine anzeigenKeine ausblenden
Titus Edelhofer am 17 Mai 2019
Yes,
ub = repmat(ub, n, 1);
Maheen Fazal am 17 Mai 2019
for i=1:n
[x(i),fval(i)]= fmincon(@(x) Simple(x),x0(i,:),A,b,[],[],lb(i,:),ub(i,:),@constraint);
end
is this a right way to execute?

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Choose a Solver 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