Optimization through iteration - help!

4 ビュー (過去 30 日間)
Jan Morawietz
Jan Morawietz 2015 年 5 月 7 日
コメント済み: Jan Morawietz 2015 年 5 月 8 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 5 月 8 日
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 2015 年 5 月 8 日
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?

サインインしてコメントする。

回答 (1 件)

Thorsten
Thorsten 2015 年 5 月 7 日
x = 1/sum(x)*x;
  3 件のコメント
Thorsten
Thorsten 2015 年 5 月 8 日
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?
Jan Morawietz
Jan Morawietz 2015 年 5 月 8 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeThird-Party Cluster Configuration についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by