Skip to content
Analytica > Blogs > An Analytica advantage over MATLAB

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   

See also

Scripting languages, Python & R

Scripting languages, Python & R

Learn to leverage special functions in Analytica through scripting language libraries or by linking existing program to an Analytica model.

More…
What is Analytica?

What is Analytica?

Analytica is a decision analysis tool that helps you generate clearer and more justified results through modeling.

More…
Using Python to parse a Shapefile

Using Python to parse a Shapefile

A shapefile (*.shp) is a binary file format used by Geographic Information Systems (GIS). I used an existing Python library (Fiona) to read and parse a shape file, and then...

More…
How to call a Python function from Analytica

How to call a Python function from Analytica

I found it pretty easy to call a Python function from Analytica using COM automation. The Component Object Model (COM) integration functionality comes included with the Analytica...

More…

Download Free Analytica


    We hate spam as much as you. We won't share your email with third parties.

    The free edition of Analytica includes these key Analytica features:
    Free Analytica has no time limit. The only constraint is it won’t let you create more than 101 variables or other objects. But your model can be quite substantial since each variable can be a multidimensional array. It also lets you explore, change inputs, and run existing models of any size (excluding features unique to the Enterprise or Optimizer editions).