Inverting Matrices

27 views
Skip to first unread message

stephe...@yahoo.com

unread,
Aug 6, 2007, 2:49:07 PM8/6/07
to AMPL Modeling Language
I am used to coding in Matlab and am new to AMPL.

If X is a parameter {A,A} where A is some set.

Is there an easy way to make a parameter that is inv(A) such that
A*inv(A) = 1 for a1=a2, and 0 otherwise?

Thanks
Stephen Finger

Robert Fourer

unread,
Aug 17, 2007, 11:16:38 PM8/17/07
to am...@googlegroups.com, Stephen Finger

AMPL isn't especially matrix-oriented, and in particular there isn't any
inverse function that applies to matrix-like objects. You could introduce a
"square" two-dimensional AMPL parameter that plays the role of a matrix, and
define a variable that is constrained to be its inverse:

param m integer > 0;
param A {1..m,1..m};
var Ainv {1..m,1..m};

subj to inv_defn {i in 1..m, j in 1..m}:
sum {k in 1..m} A[i,k] * Ainv[k,j] = (if i = j then 1 else 0);

If you just type "solve" at this point then the solver will return values
for variable Ainv that represent the inverse of A. Alternatively, you can
include these statements within a larger model that involves A's inverse in
some way.

Bob Fourer
4...@ampl.com

Reply all
Reply to author
Forward
0 new messages