help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question - sqp solver equality constraints function


From: Juan Pablo Carbajal
Subject: Re: Newbie question - sqp solver equality constraints function
Date: Thu, 22 Jun 2017 11:18:26 +0200

On Thu, Jun 22, 2017 at 9:04 AM, alexegin <address@hidden> wrote:
clear all;
global R = dlmread( "r.csv", "\t" ); # double [ 10x1 ]
global Q = dlmread( "q.csv", "\t" );# double [ 10x10 ]
global Y = dlmread( "y.csv", "\t" ); # double [ 10x1 ]
global lb = dlmread( "lb.csv", "\t" ); # double [10x1 ]
global ub = dlmread( "ub.csv", "\t" ); # double [ 10x1 ]
g = @( x ) [ sum( x( x < 0.0 ) ); sum( x( x >= 0.0 ) ) ] - [ -1.0; 1.0 ];
function z = foo( m, n )
  z = 0;
  for i = 1:rows( m )
    z = z + m( i, 1 ) * n( i, 1 );
 endfor;
endfunction;
function y = phi( x )
   global Y;
   y = foo( Y, x ) * -1;
endfunction
tic;
[ x obj info iter nf l ] = sqp( R, @phi, g, [], -1.0, 1.0);
toc;
> What am I doing wrong? Please do not tell me /everything/

ok, lets simplify...get use to do this (also try to avoid that I get
your code in a single line, makes it hard to read).

1. foo is just sum(m .* n), or m.'*n . Note that you need to
transpose, to avoid doing it every time do Y = Y.';
2. Then your cost is phi =@(x) - Y*x (so you are searching maximum
projection of x on Y. No need of global variables. Avoid them wen
possible!)
3. Your script works here with fictitious data

Y = randn(10,1).';
phi =@(x) - Y*x;
g=@(x) [sum(x(x<0.0)); sum(x(x>=0.0))] - [ -1.0; 1.0 ];
x0 = 2*rand(10,1)-1;
[x obj info iter nf l] = sqp( x0, phi, g, [], -1.0, 1.0);

possible causes of error that you need to check:
1. Make sure R (the initial guess) complies with your UB and LB
2. Make sure Y has meaningful values.
4. Remove all globals and do clear all.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]