CVX: quickstart 2 Bound-constrained Least squares

CVX: quickstart2 Bound-constrained Least squares

Least squaresに制約条件を追加する.今回は上界と下界を

minimize ||Ax-b||2
subject to l<=x<=u

  1. m = 16; n = 8;
  2. A = randn(m,n); b = randn(m,1);
  3. bnds = randn(n,2);
  4. l = min( bnds, [], 2 ); u = max( bnds, [], 2 );
  5. cvx_begin
  6. variable x(n);
  7. minimize( norm(A*x-b) );
  8. subject to
  9. x >= l;
  10. x <= u;
  11. cvx_end
本当にl<=x<=uとなっているか確認.
>> [l x u]
ans =
-2.1237 -0.1904 0.4494
-0.5046 -0.5046 0.1006
-1.2706 0.4633 0.8261
-0.3826 -0.3826 0.5362
0.6487 0.6487 0.8979
-0.1319 -0.1319 0.8257
-1.0149 -0.1472 -0.1472
-0.4711 0.1281 1.0078
制約なしLeast squaresで求めた解は
>> x_ls
x_ls =
0.1768
-0.6757
-0.7052
-0.7581
-0.2865
-0.6379
0.0581
-0.4439
となっており,確かに制約通りの解が求まっている事が分かる.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s