Problem with multidimensional arrays as arguments for interp1

46 views
Skip to first unread message

Luca

unread,
Nov 13, 2017, 3:37:10 AM11/13/17
to YALMIP
Dear Johan,
I am stuck with interp1.
I have a MILP problem solved with Gurobi in which the variable A can be represented by a piecewise linear function dependent on the variable U. A has 2 dimensions, say time T and space X. Therefore, I would like to use interp1 to interpolate the values of A at every time t and space location x. The piecewise function is always the same, and it is not dependent on either t or x, but only on U (which has to be fixed by the solver).

For example, at every t and x, my piecewise linear function is defined like:
 ui=[0 1 2]; yi=[0 2 6].

When I try to implement the problem, I define the dimensions:

T=100; X=50;

Then, the variable:
U=sdpvar(T,X, 'full');

Then i define :
 A=interp1(  repmat(reshape(ui,[1,1,3]) ,[T,X,1] ),  repmat(reshape(yi, [1,1,3]) , [T,X,1]), U, 'milp' );


The first and second arguments of interp1 have dimensions100x50x3 , while the variable U is defined as a 100x50 matrix. 

I get the error:
Index exceeds matrix dimensions.


Error in sdpvar/interp1 (line 41)
                   
out = [out;interp1(varargin{1}(i,:),varargin{2}(i,:),xij,varargin{4},varargin{5})];


Error in sdpvar/interp1 (line 21)
                varargout
{1} = interp1(varargin{1},varargin{2},reshape(varargin{3},[],1),varargin{4},varargin{5});

I suppose I am messing with the dimensions of my arrays. But I cannot understand how. When I solve the problem only considering the Time dimension (therefore removing the space dimension X), it works. 
Namely, the arguments for interp1 are 100x3 arrays, and the variable U is a 100x1 array.

Do you have any suggestions?
Thank you
Best regards


Johan Löfberg

unread,
Nov 13, 2017, 5:45:50 AM11/13/17
to YALMIP
interp1 is for, as name reveals, 1-d interpolation. Sounds like you want to do something else

For 2d, you use interp2
Message has been deleted

Luca

unread,
Nov 13, 2017, 7:11:11 AM11/13/17
to YALMIP
Dear Johan,
Thank you for your answer. 
Actually, it is a 1D interpolation, at every time t and space x.
The variable A is a function (interp1) of U.
so A(t,x)=piecewise(ui(t,x,:),yi(t,x,:),U(t,x)).
 
With ui and yi being already defined coefficients at every time t and space x. 

Johan Löfberg

unread,
Nov 13, 2017, 9:33:53 AM11/13/17
to YALMIP
Maybe the problem then is that you are trying to use interp1 in a vectorized fashion, which isn't supported

Luca

unread,
Nov 14, 2017, 1:04:20 PM11/14/17
to YALMIP
Dear Johan,
That was the problem. I substituted with for-loops instead, and it seems to work fine. 
Thank you for your time. 

Reply all
Reply to author
Forward
0 new messages