slope2_constraints

PURPOSE ^

Constructs the slope constraints

SYNOPSIS ^

function [A_slope2 b_Uslope2] = slope2_constraints(numBlocks,numOfPeriods)

DESCRIPTION ^

 Constructs the slope constraints 
--------------------------------------------------------------------------
 Date: Nov. 19, 2008, ver01
 By: Hooman Askari
--------------------------------------------------------------------------
Inputs 
--------------------------------------------------------------------------
   

--------------------------------------------------------------------------
 outputs
       
--------------------------------------------------------------------------
   
--------------------------------------------------------------------------
 Pseudo Code
   
--------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Constructs the slope constraints
0002 %--------------------------------------------------------------------------
0003 % Date: Nov. 19, 2008, ver01
0004 % By: Hooman Askari
0005 %--------------------------------------------------------------------------
0006 %Inputs
0007 %--------------------------------------------------------------------------
0008 %
0009 %
0010 %--------------------------------------------------------------------------
0011 % outputs
0012 %
0013 %--------------------------------------------------------------------------
0014 %
0015 %--------------------------------------------------------------------------
0016 % Pseudo Code
0017 %
0018 %--------------------------------------------------------------------------
0019 function [A_slope2 b_Uslope2] = slope2_constraints(numBlocks,...
0020                                                    numOfPeriods)                                         
0021                                                
0022    yA_slope = cell(numBlocks,1);     
0023    xA_slope = cell(numBlocks,1);     
0024     
0025    % a blank template to preallocate memory space to the yVector
0026    % and xVector
0027    blankTemp = sparse(1, numBlocks); 
0028    yA=[]; save yA yA; 
0029    xA=[]; save xA xA;   
0030    xT=[]; save xT xT;   
0031    index = 0;
0032         
0033     for iBlocks = 1 : numBlocks
0034         
0035            % create the lower triangular matrix see documentation
0036            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0037            yVec = blankTemp; 
0038            yVec(1, iBlocks)= 1; 
0039            
0040            yMatrixCell = cell(numOfPeriods,numOfPeriods);
0041            [yMatrixCell{:}] = deal(blankTemp);
0042 
0043            for i = 1:numOfPeriods
0044                [yMatrixCell{i,1:(i)}] = deal(yVec);    
0045            end 
0046                       
0047            yMatrix = cell2mat(yMatrixCell);
0048            yMatrix = sparse(yMatrix);
0049            
0050            % create the diagonal matrix, see documentation
0051            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052            xVec = blankTemp;
0053            xVec(1, iBlocks)= -1;
0054            
0055            % create the diagMatrix
0056            A = cell(1, numOfPeriods);
0057            [A{:}] = deal(xVec);
0058            xMatrix = blkdiag(A{:});
0059                     
0060            yA_slope{iBlocks,1}= deal(yMatrix);
0061            xA_slope{iBlocks,1}= deal(xMatrix);
0062            
0063            clear xMatrix yMatrix yVec xVec;
0064            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0065            % x in the current period T
0066            xT_Ivec = blankTemp;
0067            % x in the period T+1
0068            xT_IIvec = blankTemp;
0069 
0070            xT_Ivec(1, iBlocks)= 1;
0071            xT_IIvec(1, iBlocks)= - 1;
0072            
0073            B = cell(1, numOfPeriods);
0074            [B{:}] = deal(xT_Ivec);
0075            xT_I_MatrixCell = blkdiag(B{:});
0076            
0077            xT_II_MatrixCell = cell(numOfPeriods-1,numOfPeriods);
0078            [xT_II_MatrixCell{:}] = deal(blankTemp);
0079                       
0080            for i = 1:numOfPeriods-1
0081                [xT_II_MatrixCell{i,i+1}] = deal(xT_IIvec);    
0082            end 
0083            
0084            xT_II_MatrixCell = cell2mat(xT_II_MatrixCell);
0085            
0086            xT_Matrix = xT_I_MatrixCell(1:end-1,:) + xT_II_MatrixCell;
0087            
0088            xT_slope{iBlocks,1}= deal(xT_Matrix);
0089            
0090            clear xT_I_MatrixCell xT_II_MatrixCell xT_Matrix
0091            
0092            iBlocks;
0093            
0094           % saves the large xT matrices to a file
0095           % revise this the counter here is index and in xT is iBlocks
0096           index = index + 1; 
0097           if index >= 2000
0098                load yA; 
0099                yA =[yA; cell2mat(yA_slope)];
0100                save yA yA;
0101                clear yA yA_slope
0102 
0103                load xA; 
0104                xA =[xA; cell2mat(xA_slope)];
0105                save xA xA;
0106                clear xA xA_slope
0107                
0108                load xT;
0109                xT =[xT; cell2mat(xT_slope)];
0110                save xT xT
0111                clear xT_slope xT;              
0112                
0113                index = 0;
0114           end 
0115           
0116 end % iBlocks = 1 : numBlocks
0117 % check to see if the size of the matirx is greater than 1
0118    
0119  % pack;
0120   
0121  load yA; load xA; load xT;
0122  yA =[yA; cell2mat(yA_slope)];
0123  xA =[xA; cell2mat(xA_slope)];
0124  xT =[xT; cell2mat(xT_slope)];
0125  save yA yA; save xA xA; save xT xT
0126  clear yA xA yA_slope xA_slope xT_slope xT;  
0127   
0128  load yA; load xA; load xT
0129  [m n] = size(yA);
0130  [m1 n1] = size(xT);
0131    
0132  A_slope_01 = [xA                                   sparse(m, numBlocks*numOfPeriods)...
0133               sparse(m, numBlocks*numOfPeriods)     yA...
0134               sparse(m, numOfPeriods)               sparse(m, numOfPeriods)...
0135               sparse(m, numOfPeriods)               sparse(m, numOfPeriods)];
0136           
0137  A_slope_02 = [xT                                    sparse(m1, numBlocks*numOfPeriods)...
0138               sparse(m1, numBlocks*numOfPeriods)     sparse(m1, numBlocks*numOfPeriods)...
0139               sparse(m1, numOfPeriods)               sparse(m1, numOfPeriods)...
0140               sparse(m1, numOfPeriods)               sparse(m1, numOfPeriods)];
0141           
0142           
0143  A_slope2 = [A_slope_01; A_slope_02];
0144                          
0145  b_Uslope2 = sparse((m+m1),1);    
0146           
0147 end

Generated on Fri 30-Jul-2010 16:56:05 by m2html © 2003