Matrix of variables

Hello everyone,

I have four variables like this:

var p0;
var b;
var x;
var y;

And I want to create a matrix of these variables with dimensions (4*1) like so:

var X = [p0, b, x, y];

Could anyone please provide me with the syntax for this matrix?Furthermore, I would like to express the following constraint:

A * X < B

Where A and B are matrices of values that I have defined previously and are like:

param B :=
1 50
2 140
3 9
4 -1
5 35.77
6 -35.72
7 51.38
8 -51.32;

Thank you.

Here is an example of how you could formulate an AMPL model for the situation that you describe:

param m;  # number of constraints
set V;    # set of variables

param A {1..m, V};
param B {1..m};

var X {V};

subject to constr {i in 1..m}:
   sum {j in V} A[i,j] * X[j] <= B[i];

Then in the data, you can specify

set V := p1 b x y ;

Alternatively, if the variables will always be the same, you can just write this set definition in your model:

set V = {"p1","b","x","y"};

(Note that, in large-scale applications of linear optimization, almost all of the constraint coefficients are zero, and so it is not practical to specify coefficient matrices explicitly. For this reason, AMPL does not have a “matrix” data type.)

thanks for your response. I put your solution but the problem is not solved. I better explain once more.
I have three matrices. that the matrix A is a 4x8 matrix, the values inside of which are the numbers that I set in the .dat file. The next matrix is B with dimensions 4x1, which is also equal to the values that I set in the .dat file. But I have a matrix named X with dimensions 1*4. which are actually the variables that the objective function should estimate, whose names are: p0, beta, x, y.
And my objective function is:

var p; 
var b;
var xt;
var yt;

param x{i in 1..5};
param y{i in 1..5};

param A{i in 1..8, j in 1..4};
param B{i in 1..8};

var g{i in 1..samples} = x[i] * xt *(y[i] - yt) ; 
minimize Obj_value: sum{i in 1..samples} (p + b * (g[i])^2);

and i want to add this constraint:
A *X <= B
for example A, B and X are:

X [p, b, xt, yt]
B[3, 5,10,15]

how to write it?
thank you

Now that I can see your whole model, I think it may be easier for you to write the constraint like this:

subject to constr {i in 1..8}:
   A[i,1]*p + A[i,2]*b + A[i,3]*xt + A[i,4]*yt <= B[i];

Note that there need to be eight B values: B[i] for each i in 1..8. Also you need to define the parameter samples that appears in the definitions of g and Obj_value.

If you need help specifying the data for matrix A, you can find some examples in section 9.3 Data in tables in the AMPL book.

Thank you so much! it worked.