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

### Building electrification: heat pump technology

Lumina set out to build a useful tool to assess the benefits of heat pumps. Learn more about heat pumps and their impact.

### Navigating the heat pump landscape

Fort Collins, Lumina, and Apex Analytics have created a tool to help reduce greenhouse gas emissions by optimizing building electrification programs.

### US gas leaks much larger than previously estimated

A new Stanford-led study on natural gas leak rates from oil and gas activity across a large fraction of the US are about 3x more than previous government estimates. The

### Building electrification: heat pump technology

Lumina set out to build a useful tool to assess the benefits of heat pumps. Learn more about heat pumps and their impact.

More…

### Decision making when there is little historic precedent

Learn how to make decisions and strategic plans in uncertain situations, where historical data is not available. See how to model this in Analytica with clarity and insight.

More…

### Does GPT-4 pass the Turing test?

In 1950, Alan Turing proposed “The Imitation Game”, today known as the Turing test, as a hypothetical way of measuring whether a computer can think [1]. It stakes out the...

More…

### What is Analytica

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

More…