Skip to content

An Analytica advantage over MATLAB

I’m working on a model translation project for the California Energy Commission, going from MATLAB to Analytica. The transportation system model I’m working with has variables with many dimensions, including time, vehicle type, fuel, mode, and vintage. The MATLAB implementation includes pervasive use of the repmat (repeat matrix) and the reshape functions, which obscure the core model logic (and looks like a pain to have had to implement). As I’m translating, I’m reminded of how nice Analytica’s Intelligent Arrays are to work with, for reasons I’ll illustrate below.

Many parts of the model are conceptually straightforward. For example, fuel cost is the product of fuel cost by vehicle type and number of vehicles of each type over time. Surrounded by the reshaping and repeating function calls necessary to perform a simple element-wise multiplication, this logic takes some time to figure out within the MATLAB code:

  dollarsPerMile = repmat(reshape(fuelPrice(car,:,:),   [dimension.fuelType 1 1 dimension.Time]), [1 dimension.class dimension.vintage 1]) ./ repmat(milesPerFuelUnit, [1 1 1 dimension.Time]);   totalCost = sum(sum(sum(vehicles .* dollarsPerMile,3),2),1);

versus the Analytica implementation:

  dollarsPerMile := fuelPrice / milesPerFuelUnit;   totalCost := sum( vehicles * dollarsPerMile, class, fuelType, vintage);

Analytica’s Intelligent Array abstraction takes care of this behind the scenes, so I just need to make sure I’ve implemented the correct logic. I don’t have to think about the dimensionality of the data until it’s relevant to the logic I’m implementing. Another example: in computing what fraction of the vehicle fleet is electric I need to calculate the size of the fleet to figure out my denominator, summing over all types of vehicles. When I do compute that sum, thankfully I don’t need to remember that vehicle type is the third of five array dimensions. (As I read through the MATLAB code, my scratch paper filled with of ordered lists of dimensions for the MATLAB arrays to track what dimension was being repeated or summed.)

So, if you’re working in MATLAB and find yourself using repmat and reshape, consider letting Analytica do that unenjoyable dimension management on your behalf so you can focus on building out a model to help you analyze whatever system or problem you’re tackling. You know, the fun stuff!

Share now