How can I proceed with interpolation when both arguments are symbolic values and the the last one is a vector of my decision variables? (Error in interp1 (line91))

3 views (last 30 days)
I have a vector of 408 road gradients (decision variables) that I am trying to optimize to minimize fuel consumption. The problem is as follow: The starting point x0 is the 408 road gradients (G) already converted (the percent % is calculated as G./100). For each gradient, I have a corresponding length in meter stored in vector L. The corresponding Fuel Consumption (at fixed speed) is given as a vector of Factors (FCfac) for a set of gradients (Slope). For brevity, I provide only Slope and FCfac (see below). The problem has two type of constraints which are bounds and equalities. All constraints are linear! I tried the following with no success: G = Gradients; L = Distances; x0 = G; N = length(G); Slope = -6/100:2/100:6/100; FCfac = [3,3.5,20,200,500,800,1000];
I derive some other variables of interest as follow: VP = L.*G; El = cumsum(VP); % To obtain the elevation for the initial alignment (the one to optimize) M = Length(FCfac);
[If I want to estimate fuel consumption for my initial alignment, I do the following TotFC = sum(L.*(interp1(Slope ,FCfac,G,'pchip')));]
Constraints s = 6/100; % 1) -s <= X <= s % The lower and upper bounds. % 2) The First elevation in optimizied alignment must be the same as in the initial one. % 3) The last elevation in the optimized alignment must be the same as in the initial one.
Constraints 2 and 3 forces the starting and destination points to remain at same altitude. LB = -s*ones(N,1); UB = s*ones(N,1); Aeq = zeros(2,N); Aeq(1,1) = L(1); Aeq(end,end) = L(end); beq = zeros(2,1); beq(1) = El(1); beq(2) = El(end);
The Modeling the objFun I used symbolic math toolbox to model my objective function X = sym('x',[N,1]); % Road Gradients D = sym('D',[N,1]); % Segment Length F = sym('F',[M,1]); % Fuel Consumption Factors S = sym('S',[1,M]); % Slope range
I proceed as follow: FCfacAlg = interp1(S,F,X,'pchip'); % Extracting Factors for X just like in [A] FCSeg = D.*FCfacAlg; % Calculate fuel consumption for each segment totFC = sum(FCSeg); % Obtain the total fuel consumption for the entire alignment.
Then I substitue to obtain a function of x only, and create a function handle as follow:
totFC = subs(totFC,[S;F;D],[Slope;FCfac;L]); matlabFunction(totFC,'vars',{X},'file','objFcn');
Lastly I call the optimization routine as follow:
options = optimset('MaxFunEvals',Inf,'MaxIter',5000,... 'Algorithm','interior-point','Display','iter');
tic [xopt, fval] = fmincon(@objFcn,x0,[],[],Aeq,beq,LB,UB,[],options); toc
Although it seems logic and clear, the code is executed up to the definition of symbolic variables and returns the following:
Error in interp1 (line 91) [X,V,orig_size_v] = reshapeAndSortXandV(varargin{1},varargin{2});
Error in mainOptFCmin (line 95) FCfacAlg = interp1(S,F,X,'pchip');
Any one can help handle this? Ideas on how else to proceed? Thank you in advance!

Answers (0)

Categories

Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!