Reputation: 575
Consider the following table in GAMS:
Set i /i1*i4 /;
Table a(i,j) 'original matrix'
i1 i2 i3 i4
i1 2 0 0 0
i2 0.272727 2 0.727273 0
i3 0 0.8 2 0.2
i4 0 0 0 2;
I want to multiply the inverted matrices of a
with the following vector:
parameters v(i) /
i1 0
i2 -0.03413
i3 -0.01174
i4 0 /;
So I will end up with the following vector:
parameters B(i) /
i1 0
i2 -0.01747
i3 0.001116
i4 0
I have tried with the following:
Alias (i,j);
Parameter inva(i,j) 'inverse of a';
execute_unload 'a.gdx', i, a;
execute '=invert.exe a.gdx i a b.gdx inva';
execute_load 'b.gdx', inva;
parameter B(i);
loop(j,
loop(i,
B(i) = inva(i,j)*v(i)
)
);
My inverted matrices seems fine, but something goes wrong with the matrix/vector multiplication.
Upvotes: 1
Views: 490
Reputation: 36
Just looked at your code briefly and to me it seems that you would like to have the last loop as:
loop(j,
B(i) = inva(i,j)*v(j)
);
because you want to sum only over the columns of the matrix.
Upvotes: 2