Optimization through iteration - help!

I'm desperatley trying to optimize vector x such as its sum equals one.I need this for an optimization problem which can only be solved by iteration.. Thx for any adivce
best Jan
x = [0.125,0.125,0.125,0.125];
testf = sum(x);
test1 = 1;
while abs(test1-testf)~=0
test1 = testf;
testf = sum(x*2);
end

9 Kommentare

Geoff Hayes
Geoff Hayes am 7 Mai 2015
Jan - your above example for x already sums to one, so perhaps give a different x. Also, what rules can you apply to your array on each iteration of the loop so that it eventually sums to one? Can you add elements or remove them or scale them?
The way I understand my formula is that x (=testf) should simply be changed to
x = [0.25,0.25,0.25,0.25]
In this example they can be scaled - there exist no other contraints. After all I'm looking for some kind of solver function. I cannot use the solver functions provided by matlab since my equation inputs include the equations final output
Geoff Hayes
Geoff Hayes am 7 Mai 2015
Hmm...I misread your original values and just realized now that sum(x*2) is 1.0 which means that you are finished on the first iteration of your while loop.
So if they can be scaled, do they all have to be scaled identically or can some elements increase or decrease independent of the others?
Jan Morawietz
Jan Morawietz am 7 Mai 2015
in this example they can be scaled independently from each other
Geoff Hayes
Geoff Hayes am 7 Mai 2015
What other rules must you enforce? Presumably I can't just set the first element to one and the remaining to all zeros. Is each element constrained to a certain interval?
Jan Morawietz
Jan Morawietz am 7 Mai 2015
yes - the min bound is zero, the max. bound is one
Or maybe this example below is more intuitive:
The original matrix "weight" does not sum up to one. Now, I want to change the values of this "weight-matrix" until it does sum up to 100% -
what am I generally doing wrong here because matlab does not stop iterating
weight = repmat(0.025,1,size(Ret,2));
n = sum(weight);
while n ~= 1
n = sum(weight*0.2);
if sum(weight) == 1
break
end
end
Jan - the code never resets the weight array so you will get the same answer on each iteration of the while loop. And multiplying the weights by a number less than one will mean that
sum(weight*0.2) < sum(weight)
always since each element of weight is less than one.
Jan Morawietz
Jan Morawietz am 8 Mai 2015
true - this example is not good... but how do I include weight so that the iteration changes its inputs. Do you know of any similar example?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Thorsten
Thorsten am 7 Mai 2015

0 Stimmen

x = 1/sum(x)*x;

3 Kommentare

Jan Morawietz
Jan Morawietz am 7 Mai 2015
Bearbeitet: Jan Morawietz am 7 Mai 2015
does x stand for weight now ? / how do I implement this in the iteration process - after all i need the iteration process to find your solution by itself
thx! best Jan
Thorsten
Thorsten am 8 Mai 2015
Hi Jan, yes, x is the weight vector. But why do you need an iteration when you can get the solution in one step? Is it homework?
I need to figure out how I can program an iteration process when the changing variable is a matrix. My examples were simply illustrations of the programming structure...
In my example below, I want to change matrix r so both function outputs x and y are equal.
r = [1,1,1]; % Initial guess
x = 1.5*r; % Condtion 1
y = 2*r; % Condtion 2
while abs(x-y)~=[0,0,0]
r = x
r = y
end

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Third-Party Cluster Configuration finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 7 Mai 2015

Kommentiert:

am 8 Mai 2015

Community Treasure Hunt

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

Start Hunting!

Translated by