25.11.2015 Views

The MOSEK Python optimizer API manual Version 7.0 (Revision 141)

Optimizer API for Python - Documentation - Mosek

Optimizer API for Python - Documentation - Mosek

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

7.2. SOLVING LINEAR SYSTEMS INVOLVING THE BASIS MATRIX 93<br />

is a solution to<br />

[<br />

0 1<br />

− 1 1<br />

] [ ] [ x<br />

c<br />

1 2<br />

=<br />

x 0 6<br />

]<br />

.<br />

7.2.3 Solving arbitrary linear systems<br />

<strong>MOSEK</strong> can be used to solve an arbitrary (rectangular) linear system<br />

Ax = b<br />

using the Task.solvewithbasis function without optimizing the problem as in the previous example.<br />

This is done by setting up an A matrix in the task, setting all variables to basic and calling the<br />

Task.solvewithbasis function with the b vector as input. <strong>The</strong> solution is returned by the function.<br />

Below we demonstrate how to solve the linear system<br />

with b = (1, −2) and b = (7, 0) .<br />

[<br />

0 1<br />

− 1 1<br />

] [ ]<br />

x0<br />

=<br />

x 1<br />

[<br />

b1<br />

b 2<br />

]<br />

[ solvelinear.py ]<br />

1 from future import with statement<br />

2 ##<br />

3 # Copyright: Copyright (c) <strong>MOSEK</strong> ApS, Denmark. All rights reserved.<br />

4 #<br />

5 # File : solvelinear.py<br />

6 #<br />

7 # Purpose : To demonstrate the usage of MSK solvewithbasis<br />

8 # when solving the linear system:<br />

9 #<br />

10 # 1.0 x1 = b1<br />

11 # -1.0 x0 + 1.0 x1 = b2<br />

12 #<br />

13 # with two different right hand sides<br />

14 #<br />

15 # b = (1.0, -2.0)<br />

16 #<br />

17 # and<br />

18 #<br />

19 # b = (<strong>7.0</strong>, 0.0)<br />

20 ##<br />

21<br />

22 import mosek<br />

23<br />

24 def put a( task,<br />

25 aval,<br />

26 asub,<br />

27 ptrb,<br />

28 ptre,<br />

29 numvar,<br />

30 basis):<br />

(7.5)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!